三个会痛的石头

菜鸟的日记

Spring - Tomcat jdbc pool 配置

Spring 配置文件


<bean id="propertyConfigurer"

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:pool.properties" />

</bean>


<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource"
destroy-method="close">
<!-- 地址 -->
<property name="url">
<value>${connection.url}</value>
</property>
<!-- 驱动地址 -->
<property name="driverClassName">
<value>${connection.driverClassName}</value>
</property>
<!-- 用户名 -->
<property name="username">
<value>${connection.username}</value>
</property>
<!-- 密码 -->
<property name="password">
<value>${connection.password}</value>
</property>
<!-- 连接池是否注册JMX代理,默认true -->
<property name="jmxEnabled">
<value>${connection.jmxEnabled}</value>
</property>
<!-- 空闲时是否进行验证,检查对象是否有效,默认为false -->
<property name="testWhileIdle">
<value>${connection.testWhileIdle}</value>
</property>
<!-- 取得对象时是否进行验证,检查对象是否有效,默认为false -->
<property name="testOnBorrow">
<value>${connection.testOnBorrow}</value>
</property>
<!-- 验证间隔,避免额外验证,在此时间内若通过验证,则再次请求不会验证,默认30000 (30秒) -->
<property name="validationInterval">
<value>${connection.validationInterval}</value>
</property>
<!-- 返回对象时是否进行验证,检查对象是否有效,默认为false -->
<property name="testOnReturn">
<value>${connection.testOnReturn}</value>
</property>
<!-- 验证连接是否成功, SQL SELECT 指令至少要返回一行 -->
<property name="validationQuery">
<value>${connection.validationQuery}</value>
</property>
<!-- 多久检查一次空闲链接,并且验证空闲链接,不能设置小于1,默认5000 (5 秒) -->
<property name="timeBetweenEvictionRunsMillis">
<value>${connection.timeBetweenEvictionRunsMillis}</value>
</property>
<!-- 可以从对象池中取出的对象最大个数,为0则表示没有限制,默认为100 -->
    <property name="maxActive">  
    <value>${connection.maxActive}</value>
    </property>
    <!-- 创建连接池时初始化连接数,默认10 -->
    <property name="initialSize">
<value>${connection.initialSize}</value>
</property>
<!-- 无链接可用时最大等待秒数,超过时间会丟出错误信息  默认30000 (30 秒) -->
<property name="maxWait">
<value>${connection.maxWait}</value>
</property>
<!-- 几秒后会自我中断 默认 60 (60 秒) -->
<property name="removeAbandonedTimeout">
<value>${connection.removeAbandonedTimeout}</value>
</property> 
<!-- 空闲链接验证时间  默认 60 (60 秒) -->
<property name="minEvictableIdleTimeMillis">
<value>${connection.minEvictableIdleTimeMillis}</value>
</property>
<!-- 最小空间连接数 一般与初始化连接数相等 默认10个 -->
<property name="minIdle">
<value>${connection.minIdle}</value>
</property>
<!-- 是否记录中断事件, 默认为 false -->
<property name="logAbandoned">
<value>${connection.logAbandoned}</value>
</property>
<!-- 是否自我中断, 默认是 false -->
<property name="removeAbandoned">
<value>${connection.removeAbandoned}</value>
</property>
<!-- jdbc 拦截器 -->
<property name="jdbcInterceptors">
<value>${connection.jdbcInterceptors}</value>
</property>
</bean>



pool.properties


connection.url=jdbc\:postgresql\://localhost\:5432/sample
connection.driverClassName=org.postgresql.Driver
connection.username=postgres
connection.password=123456
connection.jmxEnabled=true
connection.testWhileIdle=false
connection.testOnBorrow=true
connection.validationInterval=30000
connection.testOnReturn=false
connection.validationQuery=select 1
connection.timeBetweenEvictionRunsMillis=30000
connection.maxActive=100
connection.initialSize=10
connection.maxWait=10000
connection.removeAbandonedTimeout=60
connection.minEvictableIdleTimeMillis=30000
connection.minIdle=10
connection.logAbandoned=true
connection.removeAbandoned=true
connection.jdbcInterceptors=org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer




阅读更多
个人分类: 数据库
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭