用spring集成的mybatis 用的dbcp连接池,oracle数据库,当网络断开恢复后,一直报错说关闭的连接 我配置了连接池的自动重连 直接从连接池获取连接也可以获取到有效的连接,就是mybatis就是不行,配置文件如下:
classpath:jdbc.properties
<!-- 配置dbcp数据源 -->
<bean id="dbcpDataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driverClass}"/>
<property name="url" value="${jdbcUrl}"/>
<property name="username" value="${user}"/>
<property name="password" value="${password}"/>
<property name="maxTotal" value="10"/>
<property name="maxIdle" value="10"/>
<property name="initialSize" value="1"/>
<property name="maxWaitMillis" value="6000"/>
<property name="defaultAutoCommit" value="true"/>
<property name="removeAbandonedOnMaintenance" value="true"/>
<property name="removeAbandonedOnBorrow" value="true"/>
<property name="removeAbandonedTimeout" value="5"/>
<property name="logAbandoned" value="true"/>
<property name= "testOnBorrow" ><value>true</value></property>
<property name= "testOnReturn" ><value>false</value></property>
<property name= "validationQuery" ><value>select sysdate from dual</value></property>
<property name= "validationQueryTimeout" ><value>1</value></property>
<property name= "timeBetweenEvictionRunsMillis" ><value>5000</value></property>
<property name= "numTestsPerEvictionRun" ><value>8</value></property>
<!-- <property name= "maxConnLifetimeMillis" ><value>30000</value></property> -->
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dbcpDataSource" />
<property name="configLocation" value="classpath:mybatis-config.xml" />
</bean>
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
<!-- 声明式事务管理 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dbcpDataSource" />
</bean>