Closed spring-projects-issues closed 12 years ago
Rossen Stoyanchev commented
Out of curiosity how did you run into this use case? Typically the AbstractHandlerMethodMapping resolvers the bean name into a bean (around line 234, in the getHandlerInternal
method) before it gets to the HandlerAdapter.
Thomas Bruyelle commented
I'm currently trying to generate api docs on my project with a Spring MVC module of Swagger. Swagger is an api docs generator for restfull webapp.
The error occurs in the MvcApiReader
class of this module.
HandlerMappings
handlerMappingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.context, HandlerMapping.class, true, false);
RequestMappingHandlerMapping
and for each element :
HanderMethods
and for each elements :
Instantiates a class MvcApiResource
which performs the handlerMethod.getBeanOfType()
and put the result in the controllerClass
attribute. (!) Here we can have CGLIB-generated class, which is the reason of this issue.
Tries to get the @RequestMapping
annotation on that controllerClass
but it fails if it's a CGBLIB generated-class -> ERROR.I'm not an expert of BeanFactory
manipulation so I'm not sure all the steps above are correct.
About bean name resolving into a bean, I'm not sure to understand what do you mean. I really think the problem is in the getBeanType()
method. The javadoc explicitly says the method doesn't return CGLIB-generated class, but actually it does.
Rossen Stoyanchev commented
Thanks for the detail.
About bean name resolving into a bean, I'm not sure to understand what do you mean. I really think the problem is in the getBeanType() method. The javadoc explicitly says the method doesn't return CGLIB-generated class, but actually it does.
I was merely referring to the fact that the bean
property of HandlerMethod can either be a String-based bean name or an actual bean instance. This helps to avoid instantiating controllers unnecessarily when we look them up on startup in the ApplicationContext. You'll see that HandlerMethod.createWithResolvedBean() can turn the bean name into a bean instance.
That aside, yes there is a bug which is why I set the fix version to 3.2 M2.
Thomas Bruyelle commented
Thank you I understand now why a bean can be a String in HadnlerMethod
.
Thomas Bruyelle opened SPR-9490 and commented
https://github.com/SpringSource/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java#L122
When
bean instanceof String
is true, the method returns the CGLIB-generated class instead of the user-defined one.ClassUtils.getUserClass()
should also wrap the return ofbeanFactory.getType( beanName )
.Affects: 3.1.1, 3.2 M1