您的位置:首页 > 编程语言 > Java开发

springboot拦截器提取@Value属性值时为空的解决方案。

2018-04-02 09:14 295 查看
@EnableWebMvc
@Configurationpublic class WebConfig extends WebMvcConfigurerAdapter {
@Beanpublic LocaleInterceptor localeInterceptor() {return new LocaleInterceptor();}
@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor( localeInterceptor() );}}

原因就是interceptor默认是不被spring context掌管的。所以还添加@bean ,加入的spring 容器下,才可以读取的spring容器内的变量值

参考链接:https://stackoverflow.com/questions/23349180/java-config-for-spring-interceptor-where-interceptor-is-using-autowired-spring-b
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  interceptor springboot