日期:2014-05-16  浏览次数:20408 次

Spring 配置文件--- 数据源配置(dbcp)

applicationContext.xml

?

<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
     http://www.springframework.org/schema/context 
	http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!-- 数据库连接配置文件 -->
	<bean id="configBean" 
			class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:jdbc.properties" />
	</bean>
<bean id="dataSource" 
		class="org.apache.commons.dbcp.BasicDataSource" 
		destroy-method="close">
		
		<property name="driverClassName" value="${driverClassName}" />
		<property name="username" value="${username}" />
		<property name="password" value="${password}" />
		<property name="url" value="${url}" />
		最大连接数量 
		<property name="maxActive" value="${maxActive}"/>
		最小空闲连接 数
		<property name="minIdle" value="${minIdle}"/>
		最大空闲连接数 
		<property name="maxIdle" value="${maxIdle}"/>
		初始化连接 数
		<property name="initialSize" value="${initialSize}"/>
		是否在自动回收超时连接的时候打印连接的超时错误  
		<property name="logAbandoned" value="${logAbandoned}"/>  
        	是否自动回收超时连接   
        <property name="removeAbandoned"  value="${removeAbandoned}"/>  
        	超时时间(以秒数为单位) 
        <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}"/>  
        	 超时等待时间(以毫秒为单位)    
        <property name="maxWait" value="${maxWait}"/>
	</bean>

</beans>
?

?

?

?

?

?

?