4

しばらくアイドル状態だった後にアプリケーションを起動すると、以下のエラーが発生していました。(Spring + Hibernate + MySQLをDBとして使用しています)

ERROR [org.hibernate.util.JDBCExceptionReporter]The last packet successfully received from the server was 74,188,684 milliseconds ago. 
The last packet sent successfully to the server was 74,188,685 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
org.hibernate.exception.JDBCConnectionException: could not execute query

以下を servlet-context.xml に追加して、この問題を解決しました。

<beans:property name="validationQuery" value="SELECT 1"/>

ここでこの質問をしましたが、これはより具体的な解決策でした.なぜそのエラーが発生したのかを知る必要があります.

上記のリンクで提供されている 1 つ目 ( autoReconnect=true で接続文字列を構成する) と 3 つ目のオプション (接続の有効性をテストするために接続プールを構成する) を試してみましたが、両方とも機能しました。それでも、なぜ最初にエラーが発生したのかわかりません。

これが更新された servlet-context.xml ファイルで、接続プールに ApacheDBCP を使用しています。

<beans:bean id="MyID" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <beans:property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <beans:property name="url" value="jdbc:mysql://localhost:17761/myDB"/>
        <beans:property name="username" value="myname"/>
        <beans:property name="password" value="mypwd"/>
        <beans:property name="maxIdle" value="5"/>
        <beans:property name="maxActive" value="20"/>
        <beans:property name="minIdle" value="5"/>
        <beans:property name="validationQuery" value="SELECT 1"/>
</beans:bean>

接続の有効期限の問題ですか?理解するのを手伝ってください。

4

1 に答える 1