HandlerInterceptor @Autowired报 null

来源:互联网 发布:淘宝一元换购怎么做 编辑:程序博客网 时间:2024/05/01 07:56
在写spring boot里面拦截器HandlerInterceptor 的时候
里面肯定要查数据库,或者缓存之类的,肯定要


@Autowired 
RedisApi redisApi;


然而一直抱null,不管是dao还是service都一样报null。


需要换个写法

@Beanpublic APIInterceptor pagePopulationInterceptor() {    return new APIInterceptor();}public void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(pagePopulationInterceptor()).addPathPatterns("/**");}

这样就能自动加载拦截器里面的啦

0 0
原创粉丝点击