Skip to content

Annotated Groovy controllers don't work properly [SPR-6268] #10935

Closed

Description

@spring-projects-issues

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:

Referenced from: commits 64fd0b0, 8e35734

1 votes, 4 watchers

Activity

  1. spring-projects-issues commented on Oct 26, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Dave Syer commented

    There is certainly a problem with Groovy classes and AnnotationUtils. Not sure if that is the one causing this problem, since the stack trace is incomplete. I'll dig around a bit, but if you have a full stack trace, is there anything related to AnnotationUtils in there?

  2. spring-projects-issues commented on Oct 26, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Szczepan Kuzniarz commented

    The rest of the stack trace is not Spring-related:

    SEVERE: Servlet.service() for servlet test threw exception
    javax.servlet.ServletException: No adapter for handler [test.TestController@d4cdd5]: Does your handler implement a supported interface like Controller?
            at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:992)
            at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:780)
            at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:726)
            at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:636)
            at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:545)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
            at java.lang.Thread.run(Thread.java:613)
    
  3. spring-projects-issues commented on Oct 26, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Dave Syer commented

    OK, fair enough. I think this is actually just a duplicate of #10419. You can confirm that by removing the refresh-interval and seeing that it works.

  4. spring-projects-issues commented on Jun 17, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Dave Syer commented

    Resolved, along with a class of similar problems requiring proxy-target-class on a scripted object.

    I have added proxy-target-class= attribute to lang:defaults/ and lang:groovy/ (any non-Groovy bean that inherits proxy-target-class="true" from the defaults and doesn't override it will throw an exception on bean creation).

    Not quite a duplicate, since #10419 involves complicated pointcuts, but probably solved by the same means.

  5. added
    type: bug
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions