Spring - 资源文件properties的配置
2014-07-05 09:18
543 查看
Spring简化了加载资源文件的配置,可以通过去加载,这个元素的写法如下:
<</span>context:property-placeholder location="classpath:jdbc.properties"/>
如果想要配置多个properties文件
<</span>context:property-placeholder location="classpath:jdbc.properties"/>
<</span>context:property-placeholder location="classpath:jdbc.properties"/>
这种方式是不被允许的,一定会出"Could
not resolve placeholder"。
解决方案:
(1) 在Spring
3.0中,可以写:
<</span>context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>
<</span>context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>
(2) 但是在Spring
2.5中,没有ignore-unresolvable属性,所以就不能使用上面的那种方法去配置,
可以改如下的格式:
<</span>bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<</span>property name="locations">
<</span>list>
<</span>value>classpath:/jdbc.properties</</span>value>
</</span>list>
</</span>property>
</</span>bean>
<</span>context:property-placeholder location="classpath:jdbc.properties"/>
如果想要配置多个properties文件
<</span>context:property-placeholder location="classpath:jdbc.properties"/>
<</span>context:property-placeholder location="classpath:jdbc.properties"/>
这种方式是不被允许的,一定会出"Could
not resolve placeholder"。
解决方案:
(1) 在Spring
3.0中,可以写:
<</span>context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>
<</span>context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>
(2) 但是在Spring
2.5中,没有ignore-unresolvable属性,所以就不能使用上面的那种方法去配置,
可以改如下的格式:
<</span>bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<</span>property name="locations">
<</span>list>
<</span>value>classpath:/jdbc.properties</</span>value>
</</span>list>
</</span>property>
</</span>bean>
相关文章推荐
- Spring加载properties配置资源文件的应用
- Spring - 资源文件properties的配置
- Spring多资源文件properties的配置
- Spring - 资源文件properties的配置
- Spring - 资源文件properties的配置
- Spring - 资源文件properties的配置
- Spring 资源文件 properties 的配置
- spring配置文件中引用外部的properties文件
- Spring配置文件中使用ref local与ref bean的区别. 在ApplicationResources.properties文件中,使用<ref bean>与<ref local>方法如下
- Spring 使用Properties配置文件 (转载)
- spring 读取properties配置文件
- java 用properties文件配置spring数据源,用spring的JdbcTemplate的queryForList查数据
- Spring 使用Properties配置文件
- spring配置文件获取其他properties文件中的值及使用
- spring读取properties和xml配置文件的方法
- Spring 使用配置文件读取jdbc.properties
- Spring 中使用jasypt对配置文件(.properties)中密码加密
- SystemProperties读取资源文件.properties文件的配置属性
- spring 配置中引用properties文件定義
- log4j.properties资源配置文件