Description
Szczepan Kuzniarz opened SPR-6268 and commented
In the following example:
package test
@Controller
class TestController {
@RequestMapping(value = "/testGroovy.do", method = RequestMethod.GET)
public String handler(HttpServletRequest request) {
return "success"
}
}
<context:annotation-config/>
<context:component-scan base-package="test"/>
<lang:groovy script-source="classpath:test/TestController.groovy" refresh-check-delay="1000"/>
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
DefaultAnnotationHandlerMapping class discovers the Groovy controller and registers a handler as it logs:
INFO: Mapped URL path [/testGroovy.do] onto handler [test.TestController@134237]
but accessing such a controller causes ServletException:
javax.servlet.ServletException: No adapter for handler [test.TestController@134237]: Does your handler implement a supported interface like Controller?
org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:992)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:780)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:726)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:636)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:545)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
I'm not 100% sure, but it seems AnnotationMethodHandlerAdapter.getMethodResolver is unable to determine proper type of the handler. It uses ClassUtils.getUserClass (which returns proxy as a type) but for Groovy script the right type is it's MetaClass (getMethodResolver should use something like ((groovy.lang.GroovyObject) handler).getMetaClass().getTheClass()).
Maybe the problem with Groovy scripts is more general, and not limited to a MVC controller case?
Affects: 3.0 RC1
Issue Links:
- <lang:groovy> tag in version 2.5 and higher doesn't work for refreshable Spring MVC endpoints [SPR-10689] #15317 lang:groovy tag in version 2.5 and higher doesn't work for refreshable Spring MVC endpoints
- AspectJ pointcut advisors are not working with Groovy script beans [SPR-5749] #10419 AspectJ pointcut advisors are not working with Groovy script beans
Referenced from: commits 64fd0b0, 8e35734
1 votes, 4 watchers