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. 增 ...
随机推荐
- hackerrank-knapsack
https://www.hackerrank.com/challenges/unbounded-knapsack 题目描述: #include <iostream> #include &l ...
- activiti并行和串行区别
多实例还有并行.串行区分.以下解释一下什么是并行与串行 并行代表同时进行,如把任务分给5个人来处理,这5个人同时会收到任务,并且可以同时处理,不受各自的影响. 串行代表工作或任务由一个人完成后,再由另 ...
- Mac 配置 Jenkins
关于 Jenkins Jenkins 是一个开源软件项目,旨在提供一个开放易用的软件平台,使持续集成变成可能. 安装 Jenkins 并配置, http://linjunpop.logdown.com ...
- OpenUDID 实现UDID替代
http://www.cnblogs.com/zhulin/archive/2012/03/26/2417860.html 补充:还有两个比较通用的开源解决方案: OpenUDID:https://g ...
- 解决 SQL Server 所有帐号无 sysadmin 权限,且未启用 SQL Server 身份验证,sa 帐号也未启用的问题
解决 未启用 SQL Server 身份验证 的问题: 1. 运行 regedit,进入注册表编辑器 2. 打开:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Micro ...
- 读取word到二进制,再转成word
static void Main(string[] args) { try { var strParams = new Dictionary<string, string>(); stri ...
- scala future
https://docs.scala-lang.org/overviews/core/futures.html https://docs.scala-lang.org/overviews/index. ...
- 由于出现以下异常,无法生成模型:“System.Data.StrongTypingException: 表“TableDetails”中列“IsPrimaryKey”的值为 DBNull。
Entity Framework (version 6.0.0.0) and MySQL Server (>= 5.7.11) 在使用EF中,从数据库中更新模型 操作.报错! 解决办法: 1. ...
- ES6,新增数据结构WeakSet的用法
WeakSet和Set类似,同样是元素不重复的集合,它们的区别是WeakSet内的元素必须是对象,不能是其它类型. 特性: 1.元素必须是对象. 添加一个number类型的元素. const ws = ...
- Standard C 之 math.h和float.h
对于C Standard Library 可以参考:http://www.acm.uiuc.edu/webmonkeys/book/c_guide/ 或者 http://www.cplusplus.c ...