博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring @Value注解问题
阅读量:6440 次
发布时间:2019-06-23

本文共 2406 字,大约阅读时间需要 8 分钟。

xml配置了下面标签:<context:property-placeholder location="classpath:xxx.properties" />

用spring的@Value注解

@Value(value="#{redis.url}")

 private String url = "";

报错,大致为track:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'recommendController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.xiu.xclk.web.controller.RecommendController.url; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'redis' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'

 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)

 

改用下面标签:

<util:properties id="settings" location="classpath:xclkweb.properties"></util:properties>

java代码改为:

@Value("#{settings['redis.url']}")

private String url = "";

OK

 

要用util标签,要引入util的xsd

xmlns:util=""

xsi:schemaLocation=" "

 

 

 

来源:https://blog.csdn.net/daihui05/article/details/7560570

你可能感兴趣的文章
PLUM_LITE 系统框图
查看>>
Linux 下 HTTP连接超时
查看>>
Js中分号使用总结
查看>>
读《从一到无穷大》
查看>>
zend studio 8 注册 码
查看>>
USACO Section 1.2 Milking Cows
查看>>
CentOS LAMP环境 配置详解
查看>>
任正非:华为为什么要坚持工业科学管理
查看>>
实现法线贴图3D模型渲染的脚本代码(附源码)
查看>>
iPhone开发面试题--葵花宝典
查看>>
05-Git
查看>>
【Yii系列】错误处理和日志系统
查看>>
python自动化开发-3
查看>>
hihoCoder 1142 三分·三分求极值
查看>>
windows 8 系统优化,体验飞一般感脚!
查看>>
特别梦境(2016-04-07 12:12)
查看>>
Pycharm注册
查看>>
插值查找
查看>>
《软件需求十步走》阅读笔记二
查看>>
random——python标准库学习
查看>>