首页 > 编程语言 > 详细

springboot拦截器中注入service失败问题

时间:2019-02-21 13:54:13      阅读:213      评论:0      收藏:0      [点我收藏+]

一般都是因为除了在拦截器之外,还需要在拦截器的配置类中,注册拦截器时没有使用spring的bean,而是使用了new创建bean造成的。

 

可参考:http://blog.csdn.net/wmh13262227870/article/details/77005920

当然,部分版本也支持以下方式:

@Configurationpublic 
class WebInterceptorLoader extends WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter{
//这里可以自动注入下interceptor

     @Autowired

private UserAuthInterceptor userAuthInterceptor;


@Override
public void addInterceptors(InterceptorRegistry registry){

//注意这里不要使用 new UserAuthInterceptor() ,否则就会出现拦截器里无法注入service的问题 
registry.addInterceptor(userAuthInterceptor).addPathPatterns("/**").excludePathPatterns("/components/*/*","/user-auth/quit");
}
}

springboot拦截器中注入service失败问题

原文:https://www.cnblogs.com/pomfor/p/10411945.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!