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 ...
随机推荐
- Linux-IP地址后边加个/8(16,24,32)是什么意思?
是掩码的位数 A类IP地址的默认子网掩码为255.0.0.0(由于255相当于二进制的8位1,所以也缩写成“/8”,表示网络号占了8位); B类的为255.255.0.0(/16) ...
- android屏蔽软键盘并且显示光标
if (android.os.Build.VERSION.SDK_INT <= 10) {//4.0以下 danielinbiti editText.setInputType(InputType ...
- 引用POPUI来实现弹窗效果,且弹窗中的内容可以点击事件
seajs.use(['../js/ui/dialog'],function(){ $('.center-button').bind('click',function(){ var $dlg = $. ...
- js中冒泡事件和捕获事件
js中冒泡事件和捕获事件: 冒泡事件:冒泡事件是从里向外,即是从被绑定元素开始一直向外到达页面的所有祖先元素都会被触发,这 一过程被称为事件冒泡.这个事件从原始元素开始一直冒泡到DOM树的最上层 捕获 ...
- 转: 从Mysql某一表中随机读取n条数据的SQL查询语句
若要在i ≤ R ≤ j 这个范围得到一个随机整数R ,需要用到表达式 FLOOR(i + RAND() * (j – i + 1)).例如, 若要在7 到 12 的范围(包括7和12)内得到一个随机 ...
- C# XML与Json之间相互转换实例详解
对于这转换其实很简单,其中最重要的就是先要引用类库.可以到官网进行下载引用http://json.codeplex.com. XML转换为Json字符串 string xml = @"< ...
- Redis在Windows环境下搭建
1. 下载Redis-Windows版本 Redis官网下载页面: http://redis.io/download Windows下Redis项目: https://github.com/MSOp ...
- PHP替换,只替换匹配到的第一个
function str_replace_limit($search, $replace, $subject, $limit=-1) { if (is_array($search)) { foreac ...
- 拒绝了对对象 '**' (数据库 'db',架构 'dbo')的 SELECT 权限
操作次数据库的用户的权限不够,因此只需要赋予相应的权限即可 MSSQL2005:具体数据库(xxx) --- 安全性---- 架构---- dbo(属性)--- 权限--- 添加--- 浏览-- [p ...
- NOR Flash擦写和原理分析 (二)
Nor Flash上电后处于数据读取状态(Reading Array Data).此状态可以进行正常的读.这和读取SDRAM/SRAM/ROM一样.(要是不一样的话,芯片上电后如何从NorFlash中 ...