Spring 3.1 can use <mvc: interceptors> in combination with @Configuration
I am moving from Spring from 3.0.5 to 3.1, since I need to create a custom RequestMappingHandlerMapping. I am facing issues in the extended RequestMappingHandlerMapping plugin - I had an existing servlet-conetxt.xml and I added WebConfig with the @Configuration annotation. But, I always get ambiguos mapping error (since the new annotation defined in ExtendedRequestMappingHandlerMapping does not work).
I have different levels of interceptors defined in the servlet-context.xml file that I want to save in the XML configuration. I want to use.
Is there a way to use the servlet-context.xml connection and at the same time extend RequestMappingHandlerMapping. If this needs to be done using @COnfiguration - can I use both @COnfiguration and servlet-context.xml? Any help would be appreciated as I tried to do this since ancient times.
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.test.config</param-value>
</context-param>
Yes, you can use it: Example:
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LocalInterceptor());
registry.addInterceptor(new SecurityInterceptor()).addPathPatterns("/secure/*");
}
}
just refer to
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html#mvc-config-interceptors for more details.
if used
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Autowired
Anything anything;
@Override
public void addInterceptors(InterceptorRegistry registry) {
log.info(anything.toString());//this will exception,how to fix?
registry.addInterceptor(new LocalInterceptor());
registry.addInterceptor(new SecurityInterceptor()).addPathPatterns("/secure/*");
}
}
@service cannot be installed on Interceptor