2024年5月26日 问题: spring boot + spring data rest 项目中 采用下面这种方式注册了 interceptor 但是不会进入 TimerInterceptor @Configuration @Slf4j public class WebCfg implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { log.info("addInterceptors enter..."); registry.addInterceptor(new TimerInterceptor());//not work } } 12345678910 @Configuration@Slf4jpublic class WebCfg implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { log.info("addInterceptors enter..."); registry.addInterceptor(new TimerInterceptor());//not work }} 解决: 拦截器 使用 Spring Data REST 后,按通用方式下配置的拦截器不生效,无法拦截住 Spring Data REST 提供的 Restful。需要特殊配置: @Bean public MappedInterceptor myMappedInterceptor() { return new MappedInterceptor(new String[]{"/**"}, new String[]{}, new TimerInterceptor()); } 1234 @Beanpublic MappedInterceptor myMappedInterceptor() {return new MappedInterceptor(new String[]{"/**"}, new String[]{}, new TimerInterceptor());} 参考: https://blog.csdn.net/weixin_45614615/article/details/109759954