数据库连接池
dbcp,c3p0,druid(德鲁伊),spring.xml配置
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 配置扫描包 -->
<context:component-scan
base-package="com.yyp.service.impl"></context:component-scan>
<context:component-scan
base-package="com.yyp.dao.impl"></context:component-scan>
<!-- 工具类加到ioc容器宏 -->
<bean class="com.yyp.util.SpringBeanHolder" />
<!-- 配置DataSource 采用spring内置的数据源,但是他没有连接池的功能 -->
<!-- 读取数据库的属性配置文件dataSource.properties -->
<context:property-placeholder
location="classpath:dataSource.properties" />
<bean id="dataSource1"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- 使用dbcp数据源,这个数据源有连接池的功能,效率会更高一些 -->
<bean id="dataSource2"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="5" />
<property name="maxActive" value="100" />
<property name="minIdle" value="3" />
<property name="maxIdle" value="5" />
<property name="maxWait" value="5000" />
</bean>
<!-- 德鲁伊连接池配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="5" />
<property name="maxActive" value="100" />
<property name="minIdle" value="3" />
<property name="maxIdle" value="5" />
<property name="maxWait" value="5000" />
</bean>
<!-- 配置jdbcTemplate -->
<bean class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>