Java 如何在Spring Boot 1.4.3中删除到mysql的非活动连接,多数据源
我使用的是SpringBoot1.4.3,我有多个数据源mysql和sqlserver sqlserver连接是远程的,当我的后端在夜间投入生产时,我的后端会中断 myserver连接很好,sqlserver连接有问题 我想在非活动时间后断开连接Java 如何在Spring Boot 1.4.3中删除到mysql的非活动连接,多数据源,java,sql-server,spring-boot,Java,Sql Server,Spring Boot,我使用的是SpringBoot1.4.3,我有多个数据源mysql和sqlserver sqlserver连接是远程的,当我的后端在夜间投入生产时,我的后端会中断 myserver连接很好,sqlserver连接有问题 我想在非活动时间后断开连接 @Configuration @EnableTransactionManagement @EnableJpaRepositories( entityManagerFactoryRef = "entityManag
@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);
}
应用程序属性
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
你试过这个吗?谢谢,我会在晚上等着看是否成功