spring里加入properties配置

直接例子了,在list里面可以加入多个properties配置:

<bean id="jdbcConfig"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:jdbc.properties</value>			 
			</list>
		</property>
	</bean>


	<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="maxActive" value="${jdbc.maxActive}" />
		<property name="maxIdle" value="${jdbc.maxIdle}" />
		<property name="minIdle" value="${jdbc.minIdle}" />
		<property name="initialSize" value="${jdbc.initialSize}" />
		<property name="validationQuery" value="${jdbc.validationQuery}" />
		<property name="testOnBorrow" value="${jdbc.testOnBorrow}" />
		<property name="validationQueryTimeout" value="${jdbc.validationQueryTimeout}" />
	</bean>


properties配置如下:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:1433/mmusic
jdbc.username=root
jdbc.password=
jdbc.maxActive=20
jdbc.maxIdle=15
jdbc.minIdle=10
jdbc.initialSize=15
jdbc.testOnBorrow=true
jdbc.validationQuery=select 1
jdbc.validationQueryTimeout=20



还有一种配置:
 < beans>

  < bean id="configproperties"

  class="org.springframework.beans.factory.config.PropertiesFactoryBean">

  < property name="location" value="file:config.properties"/>

  < /bean>

  < bean id="propertyConfigurer"

  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

  < property name="properties" ref="configproperties"/>

  < /bean>

你可能感兴趣的:(properties)