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的使用的更多相关文章

  1. spring中propertyplaceholderconfigurer简介

    Spring的框架中为您提供了一个 BeanFactoryPostProcessor 的实作类别: org.springframework.beans.factory.config.PropertyP ...

  2. spring中PropertyPlaceholderConfigurer的运用---使用${property-name}取值

    代码如下: 配置文件: jdbc.properties的代码如下: jdbc.driverClassName=org.hsqldb.jdbcDriver jdbc.url=jdbc:hsqldb:hs ...

  3. 使用Spring中的PropertyPlaceholderConfigurer读取文件

    目录 一. 简介 二. XML 方式 三. Java 编码方式 一. 简介 大型项目中,我们往往会对我们的系统的配置信息进行统一管理,一般做法是将配置信息配置与一个cfg.properties 的文件 ...

  4. Quartz 在 Spring 中如何动态配置时间--转

    原文地址:http://www.iteye.com/topic/399980 在项目中有一个需求,需要灵活配置调度任务时间,并能自由启动或停止调度. 有关调度的实现我就第一就想到了Quartz这个开源 ...

  5. Spring中文文档

    前一段时间翻译了Jetty的一部分文档,感觉对阅读英文没有大的提高(*^-^*),毕竟Jetty的受众面还是比较小的,而且翻译过程中发现Jetty的文档写的不是很好,所以呢翻译的兴趣慢慢就不大了,只能 ...

  6. Spring里PropertyPlaceholderConfigurer类的使用

    1. PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是 BeanFactoryPostProcessor接口的一个实现.PropertyPlaceho ...

  7. Spring中BeanPostProcessor

    Spring中BeanPostProcessor 前言: 本文旨在介绍Spring动态配置数据源的方式,即对一个DataSource的配置诸如jdbcUrl,user,password,driverC ...

  8. spring中context:property-placeholder/元素 转载

    spring中context:property-placeholder/元素  转载 1.有些参数在某些阶段中是常量 比如 :a.在开发阶段我们连接数据库时的连接url,username,passwo ...

  9. Spring的PropertyPlaceholderConfigurer应用

    Spring 利用PropertyPlaceholderConfigurer占位符 1. PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是BeanFa ...

随机推荐

  1. 转(JSONP处理跨域事件)

     前言: 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Soc ...

  2. 怎么给ABBYY FineReader Mac导入图像

    ABBYY FineReader Pro for Mac作为ABBYY旗下重要的OCR文字识别软件之一,专为Mac用户定制,为各种各样的任务提供了单一.全面的解决方案,它是所有需要扫描和处理数字纸质文 ...

  3. 用一条UPDATE语句交换两列的值

    在SQL UPDATE语句中,"="右侧的值在整个UPDATE语句中都是一致的,所有更新同时发生!因此以下语句将在没有临时变量的情况下交换两列的值: UPDATE table SE ...

  4. System.Web.HttpContext.Current 跟踪分析

    public static HttpContext Current { get { return ContextBase.Current as HttpContext; } set { Context ...

  5. 虚拟化之kvm与xen对比

    xen XenServer is the leading open source virtualization platform, powered by the Xen Project hypervi ...

  6. Top JavaScript Frameworks, Libraries & Tools and When to Use Them

    It seems almost every other week there is a new JavaScript library taking the web community by storm ...

  7. lambda 的使用汇总

    d=lambda x:x+1print(d(10))lambda 相当于一个轻量函数返回 d=lambda x:x+1 if x>0 else "error"print(d( ...

  8. java 框架Nutz

    http://nutzam.com/ Nutz 可以做什么? Dao -- 针对 JDBC 的薄封装,事务模板,无缓存 Ioc -- JSON 风格的配置文件,声明时切片支持 Mvc -- 注解风格的 ...

  9. ASP.NET MVC几种找不到资源的问题解决办法

    转自:http://www.cnblogs.com/xyang/archive/2011/11/24/2262003.html 在MVC中,controller中的Action和View中的.csht ...

  10. [结]Oracle trigger(触发器)摘录

    1.触发器: 是许多关系数据库系统都提供的一项技术.在ORACLE系统里,触发器类似过程和函数,都有声明,执行和异常处理过程的PL/SQL块. 触发器在数据库里以独立的对象存储,它与存储过程和函数不同 ...