spring中datasource配置

datasource配置有很多种,我介绍的一种是采用c3p0的,它的百科地址是:

http://baike.baidu.com/view/920062.htm

 

	<!-- spring加载资源文件 -->
	<bean name="propertiesConfig"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:jdbc.properties</value>
							</list>
		</property>
	</bean>
	<!-- 数据源配置 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${datasource.driverClassName}" />
		<property name="jdbcUrl" value="${datasource.url}" />
		<property name="user" value="${datasource.user}" />
		<property name="password" value="${datasource.password}" />
		<property name="minPoolSize" value="${datasource.minPoolSize}" />
		<property name="maxPoolSize" value="${datasource.maxPoolSize}" />
		<property name="maxIdleTime" value="${datasource.maxIdleTime}" />
		<property name="acquireIncrement" value="${datasource.acquireIncrement}" />
		<property name="maxStatements" value="${datasource.maxStatements}" />
		<property name="initialPoolSize" value="${datasource.initialPoolSize}" />
		<property name="idleConnectionTestPeriod" value="${datasource.idleConnectionTestPeriod}" />
		<property name="acquireRetryAttempts" value="${datasource.acquireRetryAttempts}" />
		<property name="breakAfterAcquireFailure" value="${datasource.breakAfterAcquireFailure}" />
		<property name="testConnectionOnCheckout" value="${datasource.testConnectionOnCheckout}" />
	</bean>

 下面是jdbc.properties的配置:

#datasource.driverClass=oracle.jdbc.driver.OracleDriver
datasource.driverClassName=com.mysql.jdbc.Driver
datasource.url=jdbc\:mysql\://192.168.1.1\:3306/xxx
datasource.user=root
datasource.password=123456
#Optional
datasource.minPoolSize=1
datasource.maxPoolSize=50
datasource.maxIdleTime=25000
datasource.acquireIncrement=2
datasource.maxStatements=0
datasource.initialPoolSize=2
datasource.idleConnectionTestPeriod=25000
datasource.acquireRetryAttempts=30
datasource.breakAfterAcquireFailure=true
datasource.testConnectionOnCheckout=true

 

你可能感兴趣的:(dataSource)