Spring3.x 获取properties资源文件的值

Spring3.x 获取properties资源文件的值有两种方式: 

第一种:使用<context:property-placeholder />标签 
<context:property-placeholder ignore-unresolvable="true" location="classpath*:jdbc.properties" />
然后在Spring的xml文件中就使用${jdbc.driver}获取
<property name="driverClassName" value="${jdbc.driver}" />

第二种:使用<util:properties/> 标签
<util:properties id="props" location="classpath:generic.properties" local-override="true"/>
(1)在java文件中使用@Value("#{props['..']}")获取资源文件的值
(2)在xml文件中使用#{props['jdbc.username']}获取
 <property name="username" value="#{props['jdbc.username']}" />


posted @ 2014-07-31 17:55  QuantSeven  阅读(940)  评论(0编辑  收藏  举报