반응형

Tomcat 7.0.32 + JDK 1.6.0 u37 + Spring 3.1.3 운영 중

특별한 장애 없이

Servlet.service() for servlet [xxx] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.RecoverableDataAccessException:
### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 48,092,122 milliseconds ago.  The last packet sent successfully to the server was 48,092,123 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.

위와 같은 tomcat 에러 로그가 발생했습니다.

구글링을 해보니
특정 시간동안 DB 접근이 없어서 DB 커넥션이 끊어진 상태에서
다시 DB 접근하려고 할 때 validation 체크를 할 수 있는 쿼리가 없을 때 발생하는 거 같더군요.

그래서 applicationContext.xml 중 dataSource 부분에
validationQuery 를 추가했습니다.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName">
        <value>#{properties['jdbc.driverClassName']}</value>
    </property>
    <property name="url">
        <value>#{properties['jdbc.url']}</value>
    </property>
    <property name="username">
        <value>#{properties['jdbc.username']}</value>
    </property>
    <property name="password">
        <value>#{properties['jdbc.password']}</value>
    </property>
    <property name="maxActive">
        <value>100</value>
    </property>
    <property name="validationQuery">
        <value>SELECT 1</value>
    </property>
    <property name="testWhileIdle">
        <value>true</value>
    </property>
</bean>

validationQuery 중요하게 보지 않았는데..
이런 이슈가 있더군요..

조금이나마 도움 되시길...

참고 링크

http://commons.apache.org/dbcp/configuration.html

http://fbwotjq.tistory.com/entry/IBATIS-%EC%BB%A4%EB%84%A5%EC%85%98-%EC%97%90%EB%9F%AC

 

반응형

+ Recent posts