java - Spring-jdbc-4.0.5.release:以编程方式设置 DriverManagerDataSource 连接超时
问题描述
我注意到 SQL 连接在 30 分钟后关闭,所以我试图将其增加到 60 分钟。下面是我的 Sql server 2008 的 Spring Datasource 配置类,我试图将 connectiontimeout 设置为ds.getConnectionProperties().put("socketTimeout", jdbcsocketTimeout);
但Error creating bean with name 'entityManagerFactory'
在启动应用程序时出现错误。
@Configuration
@EnableJpaRepositories
public class JpaConfiguration {
@Value("${jdbc.driverClassName}")
String jdbcDriverClassName;
@Value("${jdbc.url}")
String jdbcUrl;
@Value("${jdbc.username}")
String jdbcUsername;
@Value("${jdbc.password}")
String jdbcPassword;
@Value("${jdbc.socketTimeout}")
int jdbcsocketTimeout;
@Bean
public javax.sql.DataSource remoteDataSource() {
DriverManagerDataSource ds = new DriverManagerDataSource(jdbcUrl, jdbcUsername, jdbcPassword);
ds.setDriverClassName(jdbcDriverClassName);
System.out.println("jdbcsocketTimeout "+jdbcsocketTimeout);
//ds.getConnectionProperties().put("socketTimeout", jdbcsocketTimeout);
return ds;
}
@Bean
public Map<String, Object> jpaProperties() {
Map<String, Object> props = new HashMap<String, Object>();
props.put("hibernate.dialect", SQLServer2008Dialect.class.getName());
return props;
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setGenerateDdl(false);
hibernateJpaVendorAdapter.setDatabase(Database.SQL_SERVER);
return hibernateJpaVendorAdapter;
}
@Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager(localContainerEntityManagerFactoryBean().getObject());
}
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean() {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(this.remoteDataSource());
lef.setPackagesToScan(getClass().getPackage().getName());
lef.setJpaPropertyMap(this.jpaProperties());
lef.setJpaVendorAdapter(this.jpaVendorAdapter());
return lef;
}
}
有人可以帮我在上面的课程中设置连接超时吗?
解决方案
推荐阅读
- sql - HIVE 转换 unix 时间戳进行计算
- ruby-on-rails - 将 has_many 与多态模型一起使用
- c# - Monogame透明图像出血
- python - 当调用 train() 或 eval() 时,我可以让我的自定义 pytorch 模块表现不同吗?
- pyqt5 - 打开图像并在其上绘图
- java - 如何连接到 MySQL 数据库
- atom-editor - 我的 atom 包没有为 Elm 提供错误突出显示
- sql-server - 如何处理权限的复杂业务逻辑
- node.js - ts-node-dev 错误选项:--transpileOnly 和错误选项:--ignoreWatch
- c++ - 普通查找和隐藏