美文网首页
Spring Boot 拦截器注入service为空

Spring Boot 拦截器注入service为空

作者: _凌浩雨 | 来源:发表于2019-06-27 12:28 被阅读0次

问题

拦截器中使用 Service 为空

解决方法

在添加拦截器的 Web 配置类中使用注入的方式引用拦截器

/***
 * @author mazaiting
 * @date 2019-06-26
 * @decription Web 配置
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    /**
     * Session 拦截器
     */
    private final SessionInterceptor mSessionInterceptor;

    @Autowired
    public WebMvcConfig(SessionInterceptor mSessionInterceptor) {
        this.mSessionInterceptor = mSessionInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TestInterceptor());
        registry.addInterceptor(mSessionInterceptor);
    }
}

相关文章

网友评论

      本文标题:Spring Boot 拦截器注入service为空

      本文链接:https://www.haomeiwen.com/subject/liglcctx.html