Is it possible to wire a Spring MVC Interceptor using annotations?
annotations, autowired, interceptor, spring, spring-mvc
Solution
As far as I know, there are no ways to configure Spring MVC interceptors without XML at all.
However, there are some simplifications with `mvc` namespace in the latest versions of Spring 3.0.x (not Spring 3.0.0!):
<mvc:interceptors>
<bean class="com.vaannila.interceptor.LoggerInterceptor" />
</mvc:interceptors>
See also:
- MVC Simplifications in Spring 3.0
Problem
Is it possible to wire a Spring MVC Interceptor using annotations and if so could someone provide me with an example of how to do so? By wire via annotation I am referring to doing as little in the XML configuration as possible. For example in this configuration file I found at http://www.vaannila.com/spring/spring-interceptors.html; ``` <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:interceptors-ref="loggerInterceptor" /> <bean id="loggerInterceptor" class="com.vaannila.interceptor.LoggerInterceptor" /> ``` How little configuration could you get away with there? I imagine an `@Autowired` would remove the need to explicitly declare the bean in line 2, but would it be possible to get rid of line 1 with an annotation as well?