在Spring 3.1中可以 与@Configuration结合使用


问题内容

我正在从Spring
3.0.5迁移到3.1,因为我需要自定义RequestMappingHandlerMapping。我在扩展RequestMappingHandlerMapping的插件中遇到问题-
我已经有了servlet-
conetxt.xml,并添加了带有@Configuration批注的WebConfig。但是,我总是会遇到错误歧义映射(因为在ExtendedRequestMappingHandlerMapping中定义的新注释实际上不是takign)。

我在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/*");
 }

}

只是指


有关更多详细信息,请访问http://static.springsource.org/spring/docs/3.1.x/spring-
framework-reference/html/mvc.html#mvc-config-
interceptors。