5

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>
Visruth
  • 3,430
  • 35
  • 48
integral_dev
  • 77
  • 2
  • 8

2 Answers2

7

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.

danny.lesnik
  • 18,479
  • 29
  • 135
  • 200
0

if use

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

}

the @service can not be setting to Interceptor

john
  • 1
  • 2