在写spring boot里面拦截器HandlerInterceptor 的时候
里面肯定要查数据库,或者缓存之类的,肯定要
@Autowired
RedisApi redisApi;
然而一直抱null,不管是dao还是service都一样报null。
这样就能自动加载拦截器里面的啦
里面肯定要查数据库,或者缓存之类的,肯定要
@Autowired
RedisApi redisApi;
然而一直抱null,不管是dao还是service都一样报null。
需要换个写法
@Bean
public APIInterceptor pagePopulationInterceptor() {
return new APIInterceptor();
}
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(pagePopulationInterceptor()).addPathPatterns("/**");
}
这样就能自动加载拦截器里面的啦