---
title: "Spring框架中的PropertyPlaceholderConfigurer类 "
author: "rubyq"
date: "2011-08-26T16:57:59Z"
tags: []
categories: ["开源软件"]
slug: "spring-propertyplaceholderconfigurer"
draft: false
lastmod: "2011-08-26T16:57:59Z"
id: 1158920
url: "https://rubyq.iteye.com/blog/1158920"
---

Spring框架中的PropertyPlaceholderConfigurer类 

PropertyPlaceholderConfigurer类可以在applicationContext.xml配置文件中加入一个或者多个外部属性文件properties(注意location和locations属性)：

<!-- 一个外部文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="location" value="classpath:/conf/jdbc-mysql.properties"/>
</bean>

<!-- 多个外部文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="locations">
	<list>
	   <value>classpath*:/conf/jdbc-mysql.properties</value>  	   <value>classpath*:/conf/hibernate-mysql.properties</value>
	</list>
      </property>
</bean>
<!--引用外部文件属性用${key}-->
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
		<property name="driverClass" value="${c3p0.driverClassName}" />
		<property name="jdbcUrl" value="${c3p0.jdbcUrl}" />
        <property name="user" value="${c3p0.user}" />
        <property name="password" value="${c3p0.password}" />
        <property name="maxPoolSize" value="${c3p0.maxPoolSize}" />
        <property name="minPoolSize" value="${c3p0.minPoolSize}" />
        <property name="initialPoolSize" value="${c3p0.initialPoolSize}" />
        <property name="breakAfterAcquireFailure" value="${c3p0.breakAfterAcquireFailure}" /> 
</bean>