在Spring配置JDBC
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd "> <!-- 指定dataSource的方法,不是必须的,如果指定,能回收及时些 -->
<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver"></property>
<property name="url"
value="jdbc:mysql://localhost:3306/sufeng"></property>
<property name="username" value="root"></property>
<property name="password" value="1234567"></property>
<!-- 最大活跃数量 -->
<property name="maxActive" value="10"></property>
<!-- initialSize value="2" 表示连接池创建后,初始由2个Connection对象 -->
<property name="initialSize" value="2"></property>
<!-- 表示最小空闲数量,用于控制空闲的Connection对象的数量,表示最小数量不能低于2个 -->
<property name="minIdle" value="2"></property>
<!-- 表示最大空闲数量,用于控制空闲数量不能超过3个 -->
<property name="maxIdle" value="3"></property>
</bean> <bean id="jdbcUserDao" class="isoft.dao.JDBCUserDAO">
<!-- 注意:只能声明为dataSource,别的名不行 -->
<property name="dataSource" ref="dataSource"></property>
</bean> <!-- 注释:
连接池组件:
连接池组件中管的单元就是我们之前使用Connection对象,在连接池中可以管理Connection对象的创建和销毁。
除此之外,连接池还可以控制和管理Connection对象的数量。
连接池组件的优势:可以提高程序的稳定性;可以灵活地控制访问链接数量。-->
</beans>