问题描述
我从Spring 3.0.5迁移到3.1,因为我需要自定义RequestMappingHandlerMapping。我面临插件扩展的RequestMappingHandlerMapping问题 - 我已经存在servlet-conetxt.xml和我添加了WebConfig与@Configuration注释。但是,我总是得到错误ambiguos映射(因为在ExtendedRequestMappingHandlerMapping中定义的新注释不是有效的)。
我在servlet-context.xml中定义了各种级别的拦截器我想保留在XML配置。我想使用。
有没有办法使用servlet-context.xml的连接,同时扩展RequestMappingHandlerMapping。如果这必须使用@COnfiguration - 我可以使用@COnfiguration和servlet-context.xml?任何帮助将不胜感激,因为我一直在尝试这个很长一段时间。
< 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>
是的,你可以使用它:
示例:
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry){
registry.addInterceptor(new LocalInterceptor());
registry.addInterceptor(new SecurityInterceptor())。addPathPatterns(/ secure / *);
}
}
了解更多详情。
I am migration from Spring 3.0.5 to 3.1 since I need to have custom RequestMappingHandlerMapping. I am facing problems in plug-in of extended RequestMappingHandlerMapping - I had existing servlet-conetxt.xml and I added WebConfig with @Configuration annotation. But, I always get error ambiguos mapping (since new annotation defined in ExtendedRequestMappingHandlerMapping is not takign in effect).
I have various levels of interceptors defined in servlet-context.xml which I want to keep in XML configuration. I want to use .
Is there a way to use conjunction of servlet-context.xml and at the same time extend RequestMappingHandlerMapping. If this has to be done using @COnfiguration - can I use both @COnfiguration and servlet-context.xml? Any help would be appreciated as I have been trying this since a long time.
<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-interceptorsfor more details.
这篇关于在Spring 3.1中,可以< mvc:interceptors>与@Configuration一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!