I am using Spring boot 1.4.3, and i have multiple datasource mysql, sqlserver.
The sqlserver connection is remote and when my backend is in production in the night my backend breaks
The myserver connection is good, the sqlserver connection I'm having problems
I want disconnect after time inactive
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "entityManagerFactory",
transactionManagerRef = "transactionManager",
basePackages = { "com.xxxx" }
)
public class remoteDBConfig {
@Bean(name = "dataSourcexxxx")
@ConfigurationProperties(prefix = "bar.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean
entityManagerFactory(
EntityManagerFactoryBuilder builder,
@Qualifier("dataSourcexxxx") DataSource dataSource
) {
return builder
.dataSource(dataSource)
.packages("com.xxxx")
.persistenceUnit("xxxx")
.build();
}
@Bean(name = "transactionManagerxxx")
public PlatformTransactionManager transactionManager(
@Qualifier("entityManagerFactorySiconet") EntityManagerFactory
entityManagerFactory
) {
return new JpaTransactionManager(entityManagerFactory);
}
application.properties
bar.datasource.url=jdbc:sqlserver://4354dfgdg.no-ip.org:1433;databaseName=xxxxxx
bar.datasource.username=xxxx
bar.datasource.password=xxxx
bar.datasource.driverClassName= com.microsoft.sqlserver.jdbc.SQLServerDriver
bar.jpa.show-sql=true
bar.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
bar.jpa.hibernspring.datasource.tomcat.test-while-idle=true