Spring PropertyPlaceholderConfigurer 站位

1、 说明:

Spring的框架中,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer类可以将.properties(key/value形式)文件中一些动态设定的值(value),在XML中替换为占位该键($key$)的值,.properties文件可以根据客户需求,自定义一些相关的参数,这样的设计可提供程序的灵活性。

2、使用

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="locations">
    <list>
     <value>/WEB-INF/mail.properties</value>    //处于WEB-INF目录下的文件
     <value>classpath: conf/sqlmap/jdbc.properties</value>//注意这两种value值的写法 ,处于src目录中的,也就是class中的。
    </list>
   </property>
</bean>

3、实例

 

 

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

		<property name="locations">

			<list>

				<value>/WEB-INF/config/jdbc.properties</value>

			</list>

		</property>

	</bean>

	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

		<property name="driverClass" value="${jdbc.driverClassName}" />

		<property name="jdbcUrl" value="${jdbc.url}" />

		<property name="user" value="${jdbc.username}" />

		<property name="password" value="${jdbc.password}" />

		<property name="autoCommitOnClose" value="true"/>

		<property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>

		<property name="initialPoolSize" value="${cpool.minPoolSize}"/>

		<property name="minPoolSize" value="${cpool.minPoolSize}"/>

		<property name="maxPoolSize" value="${cpool.maxPoolSize}"/>

		<property name="maxIdleTime" value="${cpool.maxIdleTime}"/>

		<property name="acquireIncrement" value="${cpool.acquireIncrement}"/>

		<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"/>

	</bean>


 

 

你可能感兴趣的:(Spring PropertyPlaceholderConfigurer 站位)