如何在第三次春季启动时使用autoConfiguration添加类似FilterRegistrationBean
的interceptor
?或者还有其他技巧可以使用拦截吗
您必须使用WebMvcConfigurerAdapter向InterceptorRegistry注册此Interceptor,如下所示−
@Component
public class ApplicationInterceptorConfig extends WebMvcConfigurerAdapter {
@Autowired
LoggerInterceptor loggerInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loggerInterceptor);
}
}