Spring – ${} is not working in @Value--转载
原文:http://www.mkyong.com/spring/spring-is-not-working-in-value/
By mkyong | February 4, 2015 | Last Updated : February 12, 2015
A simple Spring @PropertySource example to read a properties file.
db.driver=oracle.jdbc.driver.OracleDriver
@Configuration
@PropertySource("classpath:db.properties")
public class AppConfig {
@Value("${db.driver}")
private String driver;
But the property placeholder ${} is unable to resolve in @Value, if print out the driver variable, it will display string ${db.driver} directly, instead of “oracle.jdbc.driver.OracleDriver”.
Solution
To resolve ${} in Spring @Value, you need to declare a STATICPropertySourcesPlaceholderConfigurer bean manually. For example :
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@Configuration
@PropertySource("classpath:db.properties")
public class AppConfig {
@Value("${db.driver}")
private String driver;
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
return new PropertySourcesPlaceholderConfigurer();
}
}
For XML configuration, Spring will help you to register PropertySourcesPlaceholderConfigurerautomatically.
<util:properties location="classpath:db.properties"/>
Spring – ${} is not working in @Value--转载的更多相关文章
- [转载]架构指南 : Java1.7+Eclipse luna + Maven 3.2.5 +spring 4.1.4
1. 环境配置 a) Java 1.7 b) Eclipse luna c) Maven3.2.5 d) spring 4.1.4 2. ...
- (转载)自己实现spring
您还 « 上一页 1 2 3 下一页 » 浏览 9671 次 锁定老帖子 主题:spring深入源码1 简单实现ioc机制 精华帖 (0) :: 良好帖 (2) :: 新手帖 (0) :: 隐藏帖 ( ...
- 转载:spring ,struct2 在 web.xml中的配置
转载网址:http://blog.sina.com.cn/s/blog_4c6e822d0102dv63.html <!-- Struts2 need begin--> <filt ...
- Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)
作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...
- RTP与RTCP协议介绍(转载)
RTSP发起/终结流媒体.RTP传输流媒体数据 .RTCP对RTP进行控制,同步.RTP中没有连接的概念,本身并不能为按序传输数据包提供可靠的保证,也不提供流量控制和拥塞控制,这些都由RTCP来负责完 ...
- 《Walking the callstack(转载)》
本文转载自:https://www.codeproject.com/articles/11132/walking-the-callstack Download demo project with so ...
- [转载]MVVM模式原理分析及实践
没有找到很好的MVVM模式介绍文章,简单找了一篇,分享一下.MVVM实现了UI\UE设计师(Expression Blend 4设计界面)和软件工程师的合理分工,在SilverLight.WPF.Wi ...
- [转载]:STM32为什么必须先配置时钟再配置GPIO
转载来源 :http://blog.csdn.net/fushiqianxun/article/details/7926442 [原创]:我来添两句,就是很多同学(包括我)之前搞低端单片机,到了stm ...
- [转载]从MyEclipse到IntelliJ IDEA-让你摆脱鼠标,全键盘操作
从MyEclipse转战到IntelliJ IDEA的经历 注转载址:http://blog.csdn.net/luoweifu/article/details/13985835 我一个朋友写了一篇“ ...
- TCP同步与异步,长连接与短连接【转载】
原文地址:TCP同步与异步,长连接与短连接作者:1984346023 [转载说明:http://zjj1211.blog.51cto.com/1812544/373896 这是今天看到的一篇讲到T ...
随机推荐
- Jquery AutoComplete的使用方法实例
jquery.autocomplete详解 语法: autocomplete(urlor data, [options] ) 参数: url or data:数组或者url [options]:可选项 ...
- Web API 依赖注入与扩展
与 MVC 类似, Web API 提供了System.Web.Http.Services.IDependencyResolver 接口来实现依赖注入, 我们可以很容易的用 Unity 来实现这个接口 ...
- HDU 5288 OO’s Sequence
题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
- [转] Attach、Detach和DeleteObject
原文:Attach.Detach和DeleteObject,想飞的梦想 1.CWnd Attatch和Detach的关系 首先,要明白Windows对象和MFC对象的区别. MFC对象实际上并没有把整 ...
- 31、activity 四种工作模式
一个应用通常(不一定)对应一个任务栈,相当于有个集合,保存了这个app里所有的页面栈的规则是先进后出,"进"就相当于打开了一个页面,"出"就相当于返回时关闭一个 ...
- Magento 重新安装的方法
如果之前已经成功安装Magento, 不必再下载Magento进行重新安装,很多朋友删掉所有程序文件然后再上传一个magento程序包进行重新安 装, 这样做很耗时间. 其实只需把magento的根目 ...
- Ubuntu下部署SVN+SVNManager
本文参考了一下博客,特此感谢: 灰烬之灵 一米阳光做IT.测试 环境描述:ubuntu 13.04 1.先创建svn组和svn用户: sudo addgroup svnsudo useradd ...
- fuse文件系统
用户空间文件系统(Filesystem in Userspace,简称FUSE)是操作系统中的概念,指完全在用户态实现的文件系统.目前Linux通过内核模块对此进行支持.一些文件系统如ZFS,glus ...
- iphone练习之手势识别(双击、捏、旋转、拖动、划动、长按)UITapGestureRecognizer
首先新建一个基于Sigle view Application的项目,名为GestureTest;我的项目结构如下: 往viewController.xib文件里拖动一个imageView,并使覆盖整个 ...
- position跟display、margin collapse、overflow、float这些特性相互叠加后会怎么样?
这是寒冬大神提出的一个题目,刚开始看到这题的时候完全不知道从什么地方回答起好,题目内容比较广泛,找不到针对点.后来我觉得这个题目应该能拆成几个点来回答:1.'display'.'position' 和 ...