spring常用的连接池属性文件配置

常用的4种,分别是DBCP,C3P0,Bonecp,proxool,关于这个4个连接池的具体参数设置我再另写;

 

分别说下这4种在spring中如何配置;

(一) DBCP

引入jar文件

commons-dbcp-1.2.1.jar
commons-pool-1.3.jar二个包。

spring配置文件 

 	<bean id="dataSource3" class="org.apache.commons.dbcp.BasicDataSource"

		destroy-method="close">

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

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

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

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

	</bean> 



(二) C3P0

引入jar文件

c3p0-0.9.1.2.jar

spring配置文件

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

		destroy-method="close">

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

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

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

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

	</bean>  

jdbc.properties配置文件

######C3P0 MySQL config #######  

c3p0.driverClass=com.mysql.jdbc.Driver

c3p0.url=jdbc\:mysql\://localhost\:3306/smscore?useUnicode\=true&characterEncoding\=utf8&mysqlEncoding\=utf8

c3p0.user=root

c3p0.password=*****



(三) Bonecp

引入jar文件

Bonecp-0.7.0.jar

google-collections-1.0.jar

spring配置文件 

 	<bean id="dataSource4" class="com.jolbox.bonecp.BoneCPDataSource"

		destroy-method="close">

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

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

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

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

	</bean> 


jdbc.properties配置文件

######BONECP MySQL config #######  

BONECP.driverClass=com.mysql.jdbc.Driver

BONECP.url=jdbc\:mysql\://localhost\:3306/smscore?user=root&amp;password=*****

BONECP.user=root

BONECP.password=*****


(四) proxool

引入jar文件

proxool-0.9.1.jar

 proxool-cglib.jar

spring配置文件 

 	<bean id="dataSource5" class="org.logicalcobwebs.proxool.ProxoolDataSource">	

		<property name="alias" value="QuancunPool"></property>

		<property name="driver" value="${Proxool.driverClass}"></property>

		<property name="driverUrl" value="${Proxool.url}"></property>

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

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

	</bean> 




补充

<!-- 配置DataSource -->

	<bean id="propertyConfigurer"

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

		<property name="locations">

			<list>

				<value>classpath:jdbc.properties</value>

			</list>

		</property>

	</bean>
 

你可能感兴趣的:(spring,连接池)