Spring中PropertyPlaceholderConfigurer的使用
2016-01-26 12:55
561 查看
基本的使用方法是:(1)
<bean id="propertyConfigurerForAnalysis" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>classpath:/spring/include/dbQuery.properties</value> </property> </bean>
其中classpath是引用src目录下的文件写法。
当存在多个Properties文件时,配置就需使用locations了:(2)
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:/spring/include/jdbc-parms.properties</value> <value>classpath:/spring/include/base-config.properties</value> </list> </property> </bean>
接下来我们要使用多个PropertyPlaceholderConfigurer来分散配置,达到整合多工程下的多个分散的Properties 文件,其配置如下:(3)
<bean id="propertyConfigurerForProject1" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="order" value="1" /> <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="location"> <value>classpath:/spring/include/dbQuery.properties</value> </property> </bean>
<bean id="propertyConfigurerForProject2" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="order" value="2" /> <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="locations"> <list> <value>classpath:/spring/include/jdbc-parms.properties</value> <value>classpath:/spring/include/base-config.properties</value> </list> </property> </bean>
其中order属性代表其加载顺序,而ignoreUnresolvablePlaceholders为是否忽略不可解析的 Placeholder,如配置了多个PropertyPlaceholderConfigurer,则需设置为true
至此你已经了解到了如何使用PropertyPlaceholderConfigurer,如何使用多个Properties文件,以及如何配置多个PropertyPlaceholderConfigurer来分解工程中分散的Properties文件
相关文章推荐
- Java基础知识点2:hashCode()方法
- Eclipse 下用WiFi调试手机免root
- Struts标签入门
- Material Design学习之 Sliders(详细分析,悬空气球显示进度值,附带Eclipse可以jar)
- Material Design学习之 Sliders(详细分析,悬空气球显示进度值,附带Eclipse可以jar)
- 如何做实时监控?—— 参考 Spring Boot 实现
- Spring 从零開始-05
- Eclipse如何添加、删除jar包。
- spring如何使用多个xml配置文件
- java中的编码问题
- mava 打包时,带源码包
- JAVA本地接口(JNI)
- jdk&jre FAQ
- Spring MVC学习总结(1)——Spring MVC单元测试
- Spring MVC学习总结(1)——Spring MVC单元测试
- Spring MVC学习总结(1)——Spring MVC单元测试
- 从头认识java-18.6 synchronized在其他对象上同步和ThreadLocal来消除共享对象的同步问题
- java 单例模式总结
- Eclipse CDT run报错 Binary not found
- java算法之四希尔排序(插入排序)