问题原因
拦截器加载的时间点在springcontext之前,所以在拦截器中注入自然为null
文件解决
在spring配置文件中这样写
java;gutter:true;
@Bean
public HandlerInterceptor getMyInterceptor(){
return new MyInterceptor();
}</p>
<pre><code>@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(getMyInterceptor());
super.addInterceptors(registry);
}
</code></pre>
<p>
使用bean注解提前加载,即可成功。
Original: https://www.cnblogs.com/xiaofengfeng/p/9555078.html
Author: 小锋神
Title: springboot拦截器@Autowired为null解决
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/541148/
转载文章受原作者版权保护。转载请注明原作者出处!