I'm developing an Spring Boot 1.3 based application with an EmbeddedServletContainer, managing its own DB connections. When the server is left unused for a long time (Probably over the weekend), as there could have been stale connections to the DB, I started to see the below exception trace.
Wrapped by: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Could not open connection; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982) ~[spring-webmvc-4.2.1.RELEASE.jar!/:4.2.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.2.1.RELEASE.jar!/:4.2.1.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) ~[javax.servlet-api-3.1.0.jar!/:3.1.0]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.2.1.RELEASE.jar!/:4.2.1.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar!/:3.1.0]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) ~[undertow-servlet-1.2.11.Final.jar!/:1.2.11.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) ~[undertow-servlet-1.2.11.Final.jar!/:1.2.11.Final]
at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:249) ~[spring-boot-actuator-1.3.0.M5.jar!/:1.3.0.M5]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.1.RELEASE.jar!/:4.2.1.RELEASE]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) ~[undertow-servlet-1.2.11.Final.jar!/:1.2.11.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) ~[undertow-servlet-1.2.11.Final.jar!/:1.2.11.Final]
The only way I see to fix the error is to restart the server. Is there anyway that would help the server to open a new DB connection when there are such "no connection" exceptions?
Thanks!