已经解决 spring boot 拦截器中如何注入bean的问题
@Configuration public class MyWebAppConfigurer extends WebMvcConfigurerAdapter
@Bean RequestInterceptor requestInterceptor() { return new RequestInterceptor(); }
@Component public class RequestInterceptor implements HandlerInterceptor
@Autowired private ApplicationConfiguration configuration;
// 多个拦截器组成一个拦截器链 // addPathPatterns 用于添加拦截规则 // excludePathPatterns 用户排除拦截 @Override public void addInterceptors(InterceptorRegistry registry) { //时间拦截器 registry.addInterceptor(requestExecuteTimeInterceptor()).addPathPatterns("/**"); //API请求拦截器 registry.addInterceptor(requestInterceptor()).addPathPatterns("/**").excludePathPatterns("/weixin/server"); super.addInterceptors(registry); }