Spring中C3P0数据源的配置

来源:互联网 发布:js中的引用类型 编辑:程序博客网 时间:2024/05/22 11:31
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans.xsd"><!-- 配置c3p0数据源 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close"><!-- 数据库驱动 --><property name="driverClass" value="com.mysql.jdbc.Driver" /><!-- 数据库连接串 --><property name="jdbcUrl" value="jdbc:mysql://localhost/hiber" /><!-- 数据库用户 --><property name="user" value="root" /><!-- 数据库密码 --><property name="password" value="root" /><!-- 最小连接数 --><property name="minPoolSize" value="10" /><!-- 最大连接数 --><property name="maxPoolSize" value="20" /><!-- 最大空闲的时间,单位是秒,无用的链接再过时后会被回收 --><property name="maxIdleTime" value="1800" /><!-- 数据库连接池初始化时获取的连接数  --><property name="initialPoolSize" value="2" /><!-- 在当前连接数耗尽的时候,一次获取的新的连接数 --><property name="acquireIncrement" value="2" /><!-- 每隔1800S检查数据库空闲连接 --><property name="idleConnectionTestPeriod" value="1800" /><!-- 当数据库连接失败以后尝试 重新连接的次数 --><property name="acquireRetryAttempts" value="30" /><!-- 性能消耗较大,判断是否对每个获取的连接进行校验是否有效 --><!-- 建议使用idleConnectoinTestPeriod和automaticTestTable来提升测试性能,默认:false --><property name="testConnectionOnCheckout" value="false" /><!-- JDBC标准参数,用来控制数据源内加载的PreparedStatement对象的数量但是由于缓存的statement是属于单个Connection的而不是整个连接池的,所以这项配置需要考虑多方面的因素如果maxStatement和maxStatementPerConnection都为0,则缓存关闭,模式:0 --><property name="maxStatements" value="0" /><!-- 对连接池的一种保护机制,当获取连接失败时会引起所有等待连接池来获取连接的线程抛出异常但是数据源仍然有效保留,并在下次调用getConnection时继续重新尝试获取连接如果设置为true,那么在尝试获取连接失败后,该数据源将申明已断开并永久关闭;默认:false --><property name="breakAfterAcquireFailure" value="true" /></bean></beans>

0 0
原创粉丝点击