Spring中PropertyPlaceholderConfigurer的使用
Spring中PropertyPlaceholderConfigurer的使用
在使用Spring配置获取properties文件时,在网上查到相关的资料,分享哈!!
(1)获取一个配置文件 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:./mes.properties</value>
</property>
</bean>
其中classpath是引用src目录下的文件写法。
(2)获取多个配置文件时,配置就需要使用locations
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:/resources/jdbc.properties</value>
<value>classpath:/resources/config.properties</value>
</property>
</bean>
(3)使用多个PropertyPlaceholderConfigurer来分散配置,达到整合多工程下的多个分散的Properties 文件,其配置如下:
<bean id="propertyConfigureForProject1" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="1" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="location">
<value>classpath:classpath:/resources/mes.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:/resources/jdbc.properties</value>
<value>classpath:/resources/config.properties</value>
</list>
</property>
</bean>
其中order属性代表其加载顺序,而ignoreUnresolvablePlaceholders为是否忽略不可解析的
Placeholder,如配置了多个PropertyPlaceholderConfigurer,则需设置为true
PropertyPlaceholderConfigurer还有更多的扩展应用,如属性文件加密解密等方法
Spring中PropertyPlaceholderConfigurer的使用的更多相关文章
- spring中propertyplaceholderconfigurer简介
Spring的框架中为您提供了一个 BeanFactoryPostProcessor 的实作类别: org.springframework.beans.factory.config.PropertyP ...
- spring中PropertyPlaceholderConfigurer的运用---使用${property-name}取值
代码如下: 配置文件: jdbc.properties的代码如下: jdbc.driverClassName=org.hsqldb.jdbcDriver jdbc.url=jdbc:hsqldb:hs ...
- 使用Spring中的PropertyPlaceholderConfigurer读取文件
目录 一. 简介 二. XML 方式 三. Java 编码方式 一. 简介 大型项目中,我们往往会对我们的系统的配置信息进行统一管理,一般做法是将配置信息配置与一个cfg.properties 的文件 ...
- Quartz 在 Spring 中如何动态配置时间--转
原文地址:http://www.iteye.com/topic/399980 在项目中有一个需求,需要灵活配置调度任务时间,并能自由启动或停止调度. 有关调度的实现我就第一就想到了Quartz这个开源 ...
- Spring中文文档
前一段时间翻译了Jetty的一部分文档,感觉对阅读英文没有大的提高(*^-^*),毕竟Jetty的受众面还是比较小的,而且翻译过程中发现Jetty的文档写的不是很好,所以呢翻译的兴趣慢慢就不大了,只能 ...
- Spring里PropertyPlaceholderConfigurer类的使用
1. PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是 BeanFactoryPostProcessor接口的一个实现.PropertyPlaceho ...
- Spring中BeanPostProcessor
Spring中BeanPostProcessor 前言: 本文旨在介绍Spring动态配置数据源的方式,即对一个DataSource的配置诸如jdbcUrl,user,password,driverC ...
- spring中context:property-placeholder/元素 转载
spring中context:property-placeholder/元素 转载 1.有些参数在某些阶段中是常量 比如 :a.在开发阶段我们连接数据库时的连接url,username,passwo ...
- Spring的PropertyPlaceholderConfigurer应用
Spring 利用PropertyPlaceholderConfigurer占位符 1. PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是BeanFa ...
随机推荐
- 最大化 AIX 上的 Java 性能,第 3 部分: 更多就是更好
http://www.ibm.com/developerworks/cn/aix/library/es-Javaperf/es-Javaperf3.html 最大化 AIX 上的 Java 性能,第 ...
- JS之变量的运算
js变量的特点: 1.区分大小写,这是与html及css最大的不同: 2.弱变量.通过var进行定义,无明确的数据类型. 第一部分 字符型 对于字符型的数据,常用的操作为字符的转换.字符的操作 1.字 ...
- 查看jquery绑定的事件函数
作为技术狂热分子的职业本能,看到一个技术产品的功能,总会忍不住想知道它是怎么被实现的.比如我每每看到别人网站一个很炫的界面或者很酷的功能,就忍不住打开了浏览器的控制台... 好,不扯远,说说当你想看到 ...
- TFS 强制撤销别人签出的代码
有个同事离职一段时间了,今天改一下她的代码,发现有个文件签出了,晕,而且TFS用的也是只允许单用户签出. 1,找原来的用的机器,已经被人占用了,系统已经重做. 2,只有用命令行来搞了. 大致如下: t ...
- rsyslog
http://www.rsyslog.com/ http://www.rsyslog.com/doc/v5-stable/troubleshooting/troubleshoot.html RSYSL ...
- linux服务之openfiler
架构:b/s 服务器端:封装好的linux系统 客户端:浏览器 相关包:封装好的linux系统 Openfiler imports user and group information from ce ...
- .htaccess中301强制跳转到带www前缀或不带www的域名
相信很多站长朋友都有这样的的问题出现.即带www前缀的域名与不带www前缀的顶级域名收录情况是不同的.这个问题主要是由于搜索引擎对于顶级域名与二级域名权重判定不同造成的.毫无疑问地,唯一的域名能够给你 ...
- MVC5+EF6 (附加分页功能)
我们对之前的Views à Account à Index.cshtml 进行修改以完成今天的示例. 界面样式修改前: 下面对Views à Account à Index.cshtml进行如下修改: ...
- eclipse开发Android程序sdk和avd的图标不见了
在eclipse中开发我们的Android程序时,安装sdk是必不可少的,有时候会出现sdk和avd的图标都不见了的情况,一般出现这种情况的原因是你从别处copy了一个sdk的包然后直接在引用造成的, ...
- SQL SERVER 生成ORACLE建表脚本
/****** Object: StoredProcedure [dbo].[GET_TableScript_ORACLE] Script Date: 06/15/2012 13:07:16 **** ...