问题原因

拦截器加载的时间点在springcontext之前,所以在拦截器中注入自然为null

文件解决

在spring配置文件中这样写

 @Bean
    public HandlerInterceptor getMyInterceptor(){
        return new MyInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getMyInterceptor());
        super.addInterceptors(registry);
    }

  

 

使用bean注解提前加载,即可成功。

相关文章:

  • 2019-07-02
  • 2022-01-07
  • 2021-11-27
  • 2022-12-23
  • 2021-07-09
  • 2022-02-21
猜你喜欢
  • 2022-12-23
  • 2021-06-09
  • 2021-11-01
  • 2021-07-17
  • 2022-12-23
  • 2021-04-18
  • 2021-10-14
相关资源
相似解决方案