Spring @Value注解问题
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="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"
来源:https://blog.csdn.net/daihui05/article/details/7560570
Spring @Value注解问题的更多相关文章
- Spring MVC注解的一些案列
1. spring MVC-annotation(注解)的配置文件ApplicationContext.xml <?xml version="1.0" encoding=& ...
- Spring系列之Spring常用注解总结
传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...
- spring @condition 注解
spring @condition注解是用来在不同条件下注入不同实现的 demo如下: package com.foreveross.service.weixin.test.condition; im ...
- spring mvc(注解)上传文件的简单例子
spring mvc(注解)上传文件的简单例子,这有几个需要注意的地方1.form的enctype=”multipart/form-data” 这个是上传文件必须的2.applicationConte ...
- Spring的注解方式实现AOP
Spring对AOP的实现提供了很好的支持.下面我们就使用Spring的注解来完成AOP做一个例子. 首先,为了使用Spring的AOP注解功能,必须导入如下几个包.aspectjrt.jar,asp ...
- Spring 之注解事务 @Transactional
众所周知的ACID属性: 原子性(atomicity).一致性(consistency).隔离性(isolation)以及持久性(durability).我们无法控制一致性.原子性以及持久性,但可以 ...
- 数据库事务中的隔离级别和锁+spring Transactional注解
数据库事务中的隔离级别和锁 数据库事务在后端开发中占非常重要的地位,如何确保数据读取的正确性.安全性也是我们需要研究的问题.ACID首先总结一下数据库事务正确执行的四个要素(ACID): 原子性(At ...
- Spring JSR-250注解
Java EE5中引入了“Java平台的公共注解(Common Annotations for the Java Platform)”,而且该公共注解从Java SE 6一开始就被包含其中. 2006 ...
- 【SSM 2】spring常用注解
声明:以下观点,纯依据个人目前的经验和理解,有不当之处,多指教! 一.基本概述 注解(Annotation):也叫元数据.一种代码级别的说明.它是JDK1.5及以后版本引入的一个特性,与类.接口.枚举 ...
- atititt.java定时任务框架选型Spring Quartz 注解总结
atititt.java定时任务框架选型Spring Quartz 总结 1. .Spring Quartz (ati recomm) 1 2. Spring Quartz具体配置 2 2.1. 增 ...
随机推荐
- 服务器保存所有用户的操作指令(history)
参考地址:https://helpcdn.aliyun.com/knowledge_detail/41210.html #!/bin/bash LOGIP=`who -u am i 2>/dev ...
- php分享二十三:字符编码
1:ASCII 在计算机中,所有的数据在存储和运算时都要使用二进制数表示(因为计算机用高电平和低电平分别表示1和0),例如,像a.b.c.d这样的52个字母(包括大写).以及0.1等数字还有一些常用的 ...
- Android入门-新手如何成功创建一个Android小应用
原文:http://android.eoe.cn/topic/summary 第一课程:Building Your First App [本课内容简介]欢迎加入到安卓应用的开发大潮中!这门课程会教授你 ...
- win10下快捷命令
win10下可在win+r的输入框中: 1.gpedit.msc //本地组策略编辑器 2.regedit //注册表 3.secpol.msc //本地安全策略 4.mstsc ...
- Java之JDBC①
JDBC工具准备:Mysql(数据库). MyEclipse(开发工具).Navicat(数据库管理工具) JDBC编程步骤·加载驱动程序:class.forName(driverClass); ...
- Windows系统环境变量path优先级测试报告
转自:http://bluekylin.cnblogs.com/archive/2005/12/16/298797.html 总以为自己很已经会操作windows了,今天在它帮助中看到一大片还不知道的 ...
- Java 格式化数字
; ){ DecimalFormat df = "); String xs = df.format(x); System.out.println(xs); x++; } 将 1 格式化为 0 ...
- 每日英语:Boost Your Balance; Avoid Falls
If you find yourself needing to sit down to take off your shoes, it might be time to start paying at ...
- 【Socket】linux网络扫描程序开发
1.mystery引入 1)系统入侵步骤:系统发现->漏洞探测->漏洞利用->痕迹清除 2)扫描器分类:主机与网络扫描器:端口服务扫描器:服务漏洞扫描器 3)T ...
- Asp.Net MVC TryUpdateModel使用说明
修改功能每个网站里都有,也有很多写法 写法1:要修改的字段刚好等于表中的字段 [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edi ...