PostgreSQL 9.6をデータソースとして使用するSpringブートv 1.5.1.RELEASEアプリケーションがあります。でも、アイドル時私のアプリは、Postgresのに接続されたままですが、接続が失われた場合、その後アプリが再接続して、代わりにスローしません:JdbcTemplateと複数のデータソースを使用したSpringブート自動再接続
org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.postgresql.util.PSQLException: This connection has been closed.
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:342) ~[spring-jdbc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:366) ~[spring-jdbc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.jdbc.support.SQLErrorCodesFactory.getErrorCodes(SQLErrorCodesFactory.java:212) ~[spring-jdbc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.setDataSource(SQLErrorCodeSQLExceptionTranslator.java:134) [spring-jdbc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.<init>(SQLErrorCodeSQLExceptionTranslator.java:97) [spring-jdbc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.jdbc.support.JdbcAccessor.getExceptionTranslator(JdbcAccessor.java:99) [spring-jdbc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:649) [spring-jdbc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
私はJPAを使用していないと私は私が来るTomcatのプールを使用しています信じているが、 spring-boot-startterを使って、hereとhereについての議論を読んでみました。私のプロパティファイルでは、私が試してみました:
#spring.datasource.tomcat.test-on-borrow=true
#spring.datasource.tomcat.validation-query=SELECT 1
#spring.datasource.tomcat.test-while-idle=true
#spring.datasource.tomcat.time-between-eviction-runs-millis=3600000
#spring.datasource.tomcat.validation-query=SELECT 1
#spring.datasource.dbcp2.test-on-borrow=true
#spring.datasource.dbcp2.validation-query=SELECT 1
spring.datasource.test-on-borrow=true
spring.datasource.validation-query=SELECT 1
しかし、私はこのように構成された、2つのデータソースを使用しています:
@Configuration
public class DatabaseConfiguration
{
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.ds_pgsql_rtmain")
public DataSource rtmainDataSource()
{
DataSource dataSource = DataSourceBuilder.create().build();
return dataSource;
}
@Bean
@ConfigurationProperties(prefix = "spring.ds_pgsql_pdns")
public DataSource pdnsDataSource()
{
return DataSourceBuilder.create().build();
}
@Bean
@Primary
public JdbcTemplate rtmainJdbcTemplate(DataSource rtmainDataSource)
{
return new JdbcTemplate(rtmainDataSource);
}
@Bean
public JdbcTemplate pdnsJdbcTemplate(@Qualifier("pdnsDataSource") DataSource pdnsDataSource) {
return new JdbcTemplate(pdnsDataSource);
}
}
私は、問題は、私は設定しなかったということであるかどうかわからないんだけどデータプールを正しく設定するか、手動でデータソースを設定してもプールが機能しないためです。または、他の何か。お手伝いをさせていただきますようお願い申し上げます。
優秀、ありがとうございます!!!! –