Merge branch '6.2.x'

This commit is contained in:
rstoyanchev
2025-01-28 15:37:38 +00:00
6 changed files with 54 additions and 11 deletions

View File

@@ -309,15 +309,19 @@ public class HandlerMethod extends AnnotatedMethod {
}
/**
* If the provided instance contains a bean name rather than an object instance,
* the bean name is resolved before a {@link HandlerMethod} is created and returned.
* If the {@link #getBean() handler} is a bean name rather than the actual
* handler instance, resolve the bean name through Spring configuration
* (e.g. for prototype beans), and return a new {@link HandlerMethod}
* instance with the resolved handler.
* <p>If the {@link #getBean() handler} is not String, return the same instance.
*/
public HandlerMethod createWithResolvedBean() {
Object handler = this.bean;
if (this.bean instanceof String beanName) {
Assert.state(this.beanFactory != null, "Cannot resolve bean name without BeanFactory");
handler = this.beanFactory.getBean(beanName);
if (!(this.bean instanceof String beanName)) {
return this;
}
Assert.state(this.beanFactory != null, "Cannot resolve bean name without BeanFactory");
Object handler = this.beanFactory.getBean(beanName);
Assert.notNull(handler, "No handler instance");
return new HandlerMethod(this, handler, false);
}