在Spring Boot 2项目中,我使用了工作正常的简单拦截器。但是,在创建自定义HandlerAdapter
和SimpleUrlHandlerMapping
之后,拦截器再也不会执行。
public class RequestMonitoringInterceptor extends HandlerInterceptorAdapter {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
logger.debug("preHandle");
return super.preHandle(request, response, handler);
}
...
}
并在我的WebConfig
中注册为:
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Bean
public RequestMonitoringInterceptor requestMonitoringInterceptor() {
return new RequestMonitoringInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(requestMonitoringInterceptor());
}
}
知道我错过了什么吗?