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
@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
相关文章推荐
- arcgis提取单个属性值
- SharePoint 部署时报错: 未能提取此解决方案中的cab文件
- Spring中利用配置文件和@value注入属性值
- php正则提取img所有属性值
- QQ2012安装不了怎么办?“提取安装文件失败”的解决方案
- 主题提取 解决方案
- SharePoint 部署时报错: 未能提取此解决方案中的cab文件
- spring mvc Controller中使用@Value无法获取属性值
- Spring中利用配置文件和@value注入属性值代码详解
- webpack4 系列教程(三): 多页面解决方案--提取公共代码
- JAVA 从项目的 properties 文件中 提取 属性值
- Python读取json文件,并转化为字典进行提取字段(出现索引must be int,not str)解决方案
- spring boot中static字段用@Value注解不进去解决方案
- SQL Server 2008空间数据应用系列十一:提取MapInfo地图数据中的空间数据解决方案
- WPF给属性加动画后不能修改属性值解决方案
- JSON对象属性名与属性值的提取
- 使用 lxml 中的 xpath 高效提取文本与标签属性值
- ORA-01405: 提取的列值为 NULL--报错原因及解决方案
- “PPT中如何插入和提取swf文件”的解决方案
- 老赵的《趣味编程:从字符串中提取信息》的一个解决方案