2015-05-14 71 views
3

我在SpringBoot中使用JPA創建了應用程序。 當我失去了連接我的應用程序給我的錯誤:如何在JPA中重新打開連接

WARN 6812 --- [io-8080-exec-42] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 17002, SQLState: 08006
ERROR 6812 --- [io-8080-exec-42] o.h.engine.jdbc.spi.SqlExceptionHelper : IO Error: Socket read timed out

estabilishin方面,我不能用我的EntityManager之後,因爲我得到:

WARN 6812 --- [io-8080-exec-50] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 17008, SQLState: 08003
ERROR 6812 --- [io-8080-exec-50] o.h.engine.jdbc.spi.SqlExceptionHelper : Closed Connection

我的連接屬性:

spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@...:..:..
spring.datasource.username=...
spring.datasource.password=...
spring.datasource.test-on-borrow=true
spring.datasource.test-while-idle=true
spring.datasource.validation-query=SELECT 1;

如何重新連接數據庫連接?

回答

0

嘗試增加外部連接池,如HikariCP,因爲春天開機後會自動檢測並使用它:如果您使用JDBC4驅動

If HikariCP is available we will use it.

,連接池將驗證它遞給之前的連接您。如果您使用的是較舊的驅動程序,您需要設置該屬性:從DOC

connectionTestQuery

If your driver supports JDBC4 we strongly recommend not setting this property. This is for "legacy" databases that do not support the JDBC4 Connection.isValid() API. This is the query that will be executed just before a connection is given to you from the pool to validate that the connection to the database is still alive. Again, try running the pool without this property, HikariCP will log an error if your driver is not JDBC4 compliant to let you know. Default: none

+0

:「如果你使用的彈簧引導啓動-JDBC或彈簧引導起動數據JPA‘首發的POM’你會自動獲得對tomcat-jdbc的依賴。「現在的問題是@Son是否使用了起始POM。 – sodik

+0

是的,我有jdbc和data-jdbc。 斷開連接後是否有其他選項可以打開新的連接? – Son

相關問題