`
jimichan
  • 浏览: 277894 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

spring 使用注解装配的Bean如何使用property-placeholder属性配置中的值

    博客分类:
  • java
阅读更多

很久没动笔了

 

spring 使用注解装配的Bean如何使用property-placeholder属性配置中的值

 

这个问题不大不小,以前偷懒凡是碰到需要引用属性文件中的类时就改用xml来配置。

 

今天看了下spring 3 的El,看来有更简单的解决方式,这个自己一直还不知道,赶不上时代了

 

在XML配置文件中配置一个util:properties

 

 

<context:property-placeholder location="/WEB-INF/config.properties"/>

<util:properties id="properties" location="/WEB-INF/config.properties"/>

 

然后就可以在类中使用注解

 

 

@Value("#{properties['jdbc.url']}")

private String jdbcurl;

 

方便多了

0
0
分享到:
评论
5 楼 haiyangyiba 2015-03-18  
jimichan 写道
果然3.1.0.M2不行,切换到 3.1.0.RELEASE 就可以使用@Value("${jdbc.url}")的方式了

兄台你的评论正解
4 楼 jimichan 2012-03-28  
果然3.1.0.M2不行,切换到 3.1.0.RELEASE 就可以使用@Value("${jdbc.url}")的方式了
3 楼 PeTiRo 2012-03-20  
最低哪个版本 不清楚 但3.1 肯定行的
2 楼 jimichan 2012-03-14  
PeTiRo 写道
<context:property-placeholder location="/WEB-INF/config.properties"/>@Value("${jdbc.url}")
private String jdbcurl;

需要哪个版本,我怎么没生效
1 楼 PeTiRo 2012-03-14  
<context:property-placeholder location="/WEB-INF/config.properties"/>@Value("${jdbc.url}")
private String jdbcurl;

相关推荐

Global site tag (gtag.js) - Google Analytics