spirn-boot如何在自定义spring-boot启动中添加拦截器



如何在第三次春季启动时使用autoConfiguration添加类似FilterRegistrationBeaninterceptor?或者还有其他技巧可以使用拦截吗

您必须使用WebMvcConfigurerAdapter向InterceptorRegistry注册此Interceptor,如下所示−

@Component
public class ApplicationInterceptorConfig extends WebMvcConfigurerAdapter {
@Autowired
LoggerInterceptor loggerInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loggerInterceptor);
}
}

最新更新