未使用自定义处理程序映射/适配器调用Spring Boot拦截器

时间:2018-10-31 12:07:55

标签: spring spring-mvc spring-boot

在Spring Boot 2项目中,我使用了工作正常的简单拦截器。但是,在创建自定义HandlerAdapterSimpleUrlHandlerMapping之后,拦截器再也不会执行。

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());
    }
}   

知道我错过了什么吗?

0 个答案:

没有答案