In Spring 3.1 can <mvc:interceptors> be used in conjunction with @Configuration

跟風遠走 提交于 2019-11-30 10:00:33

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 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!