我有一个Spring应用程序工作正常,但在应用程序(夜间)长时间不活动时,在早上访问它时无法连接到数据库。 这肯定与sql server超时有关。
我添加了一些连接池属性的更改,还包括验证查询,然后重新构建应用程序并部署它们。 它没有解决问题;连接工作到第二天早上再次抛出相同的错误。
我的担忧:
技术堆栈:
Apache-Tomcat 7.0.53
MS SQL Server 2012
java-version 1.7
spring.framework.version 4.0.2.RELEASE
hibernate-core 4.3.4.Final
hibernate-entitymanager 4.3.4.Final
jtds 1.3.1
applicationContext.xml
<jpa:repositories base-package="PACKAGE_NAME"
entity-manager-factory-ref="entityManagerFactoryXXX"
transaction-manager-ref="transactionManagerXXX" />
<bean id="dataSourceXXX" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="url" value="${XXX.jdbc.url}" />
<property name="username" value="${XXX.jdbc.username}" />
<property name="password" value="${XXX.jdbc.password}" />
<property name="initialSize" value="3" />
<property name="maxActive" value="10" />
<property name="maxWait" value="30000" /> <!-- (30 secs which is the default value) -->
<property name="maxIdle" value="15" />
<property name="minIdle" value="5" />
<property name="validationQuery" value="SELECT 1" />
<property name="validationInterval" value="30000" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="120" />
<property name="logAbandoned" value="true" />
<property name="suspectTimeout" value="90" />
<property name="timeBetweenEvictionRunsMillis" value="120000" />
<property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="true" />
<property name="testWhileIdle" value="true" />
<property name="jdbcInterceptors" value="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer" />
</bean>
<!-- XXX JPA Entity Manager Factory -->
<bean id="entityManagerFactoryXXX" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="persistenceUnitXXX"/>
<property name="dataSource" ref="dataSourceXXX"/>
<property name="persistenceProviderClass" value="org.hibernate.jpa.HibernatePersistenceProvider"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<!-- <prop key="hibernate.connection.isolation">2</prop> -->
</props>
</property>
</bean>
<!-- XXX Transaction Manager Factory -->
<bean id="transactionManagerXXX" class="org.springframework.orm.jpa.JpaTransactionManager" >
<property name="entityManagerFactory" ref="entityManagerFactoryXXX" />
<qualifier value="XXX"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManagerXXX" />
<!-- End XXX -->
堆栈追踪:
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.TransactionException: JDBC begin transaction failed:
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:430)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:420)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:257)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy58.createMetsFiles(Unknown Source)
......
Caused by: javax.persistence.PersistenceException: org.hibernate.TransactionException: JDBC begin transaction failed:
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1771)
at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:64)
at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:67)
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)
... 45 more
Caused by: org.hibernate.TransactionException: JDBC begin transaction failed:
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:76)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:162)
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1435)
at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:61)
... 47 more
Caused by: java.sql.SQLException: I/O Error: Software caused connection abort: recv failed
at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1093)
at net.sourceforge.jtds.jdbc.TdsCore.submitSQL(TdsCore.java:938)
at net.sourceforge.jtds.jdbc.JtdsConnection.setAutoCommit(JtdsConnection.java:2312)
at sun.reflect.GeneratedMethodAccessor115.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80)
at com.sun.proxy.$Proxy14.setAutoCommit(Unknown Source)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:72)
... 50 more
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.io.DataInputStream.readFully(DataInputStream.java:195)
at java.io.DataInputStream.readFully(DataInputStream.java:169)
at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:850)
答案 0 :(得分:0)
请在禁用Tomcat HTTP监视器后尝试。 禁用监视器的步骤是: 工具 - &gt;服务器 - &gt;选择服务器 - &gt;切换启用HTTP监视器