@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(myIntercptor()).addPathPatterns("/**");
}
//攔截器
@Bean
MyInterceptor myIntercptor(){
return new MyInterceptor();
}
}
spring組態檔掃描到了這個類 但是攔截器沒起作用
如果在mvc 的組態檔配置就有用
uj5u.com熱心網友回復:
是不是MyInterceptor沒有注入的問題,可以在別的地方創建MyInterceptor物件,然后在這里注入進來使用還有一種方法,是不是可以直接用new MyInterceptor().addPathPatterns("/**")
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/31097.html
標籤:Web 開發
