Announcement Announcement Module
Collapse
No announcement yet.
HandlerInterceptors for annotated Controllers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HandlerInterceptors for annotated Controllers

    How do you specify HandlerInterceptors for annotated Controllers?

    Here's what I've tried so far:

    HandlerInterceptors are added to a HandlerMapping. (See
    http://static.springframework.org/sp...ng-interceptor)

    Knowing this, I look at the 2.5.6 PetClinic example's petclinic-servlet.xml. I see a comment saying that DefaultAnnotationHandlerMapping is enabled by default, and that the declared AnnotationMethodHandlerAdapter is overriding the default.

    Since DefaultAnnotationHandlerMapping has the word 'HandlerMapping' in it, and since AnnotationMethodHandlerAdapter overrides that default, I figure I should just add an 'interceptors' property on the AnnotationMethodHandlerAdapter declaration, like so:

    <property name="interceptors">
    <list>
    <ref bean="petClinicHandlerInterceptor"/>
    </list>
    </property>

    But DefaultAnnotationMethodHandlerAdapter doesn't have an interceptors setter after all, because I get this error:

    org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'interceptors' of bean class [org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter]: Bean property 'interceptors' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

    Any ideas on what to try next?

  • #2
    I suggest you read the comment a bit better .

    Add a DefaultAnnotationHandlerMapping to the xml and to that you can add the interceptors (just like any other spring provided HandlerMapping implementation). The DefaultAnnotationhandlerMapping NEEDS a AnnotationMethodHandlerAdapter (also registered by default btw) to execute @Controllers. If you want to override the default settings for that HandlerAdapter you need to register it in the context.

    Comment

    Working...
    X