4

我正在开发一个在 Heroku 上并使用 ClearDB 的 Spring hibernate 项目。当我的页面空闲一段时间(几乎一分钟)然后我向服务器发送一些请求时,我收到如下错误:

HTTP ERROR 500

Problem accessing /authenticate.action. Reason:

Communications link failure

Last packet sent to the server was 16 ms ago.; nested exception is    org.hibernate.exception.JDBCConnectionException: Communications link failure

Last packet sent to the server was 16 ms ago.
Caused by:

org.springframework.dao.DataAccessResourceFailureException: Communications link failure

Last packet sent to the server was 16 ms ago.; nested exception is org.hibernate.exception.JDBCConnectionException: Communications link failure

Last packet sent to the server was 16 ms ago.
at     org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:631)
at     org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:104)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:403)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at sun.proxy.$Proxy33.authenticate(Unknown Source)
Caused by: org.hibernate.exception.JDBCConnectionException: Communications link failure

Last packet sent to the server was 16 ms ago.
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:131)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at sun.proxy.$Proxy75.executeQuery(Unknown Source)

我尝试在网上查找答案,并进行了一些配置设置,如下所示:

这是我的数据源配置:

<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<beans:property name="url" value="#{ 'jdbc:mysql://' + @dbUrl.getHost() +  @dbUrl.getPath()  + '?reconnect=true'}"/>
<beans:property name="username" value="#{ @dbUrl.getUserInfo().split(':')[0] }"/>
<beans:property name="password" value="#{ @dbUrl.getUserInfo().split(':')[1] }"/>
<beans:property name="minEvictableIdleTimeMillis" value="1800000"/>

每次我让页面闲置一分钟左右时,我仍然会收到错误消息。如果我对服务器的请求不间断,我不会收到此错误。

我的理解是,这与连接池中的空闲连接有关。当我在本地机器上运行数据库时,我从来没有遇到过这个错误。我只在 Heroku 上收到此错误。有没有其他人有类似的问题?

谢谢,基兰

4

0 回答 0