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 ...
随机推荐
- QQ登入(3)QQ空间分享-无需登入
public void myclick2(View v){ //QZone分享, SHARE_TO_QQ_TYPE_DEFAULT 图文,SHARE_TO_QQ_TYPE_IMAGE 纯图 ,SHAR ...
- Heap Only Tuples (HOT)
Introduction ------------ The Heap Only Tuple (HOT) feature eliminates redundant index entries and a ...
- 007. 自定义ListBox的item的宽高, 字体居中
/// <summary> /// 自定义ListBox的item的宽高, 字体居中 /// </summary> /// <param name="sende ...
- js防止回车(enter)键提交表单及javascript中event.keycode
如何防止回车(enter)键提交表单,其实很简单,就一句话.onkeydown="if(event.keyCode==13)return false;"把这句写在from标签里 ...
- ExtJs学习之Window
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- openstack(liberty): 简单网络连接图
openstack起初的网络部分是和计算核心nova合在一起的,后来被拆分出来,独立成为一个模块, 现在名为Neutron. 本博文是学习记录,记录的是基于GRE tunnel技术的neutron和计 ...
- Microsoft SQL Server Management Studio 导出触发器脚本
- MySQL指定mysqld启动时所加载的配置文件
mysqld.exe --init-file=file_name 以下为配置文件参数优化和中文详解: [client]port = 3306socket = /tmp/mysql.sock [mysq ...
- bzoj1015 星球大战
Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球.这些星球通过 ...
- android学习笔记45——android的数据存储和IO
android的数据存储和IO SharedPreferences与Editor简介 SharedPreferences保存的数据主要是类似于配置信息格式的数据,因此其保存的数据主要是简单的类型的ke ...