This configuration solve problem with following error:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.RecoverableDataAccessException: PreparedStatementCallback; SQL XXXXXXXXXXXXXXXXXX; Communications link failure
The last packet successfully received from the server was 30,184,929 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 30,184,929 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
<Resource auth="Container1" driverClassName="com.mysql.jdbc.Driver" maxActive="20" maxIdle="10" maxWait="120" testWhileIdle="true" validationQuery="select 1" name="jdbc/myapp" password="passwd" type="javax.sql.DataSource" url="jdbc:mysql://127.0.0.1/mydb?autoReconnect=true&useOldAliasMetadataBehavior=true" username="user"/>
In detail this lines validate connections before use and eliminates closed ones:
maxActive=”20″
maxIdle=”10″
maxWait=”120″
testWhileIdle=”true”
validationQuery=”select 1″