如何在Spring Boot应用程序中设置Oracle数据库连接超时 [英] How to set oracle db connection timeout in spring Boot application
本文介绍了如何在Spring Boot应用程序中设置Oracle数据库连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在Spring Boot应用程序中设置Oracle DB连接超时.我该如何设置?
I have to set Oracle DB connection timeout in Spring Boot application. How can I set it?
在WebLogic服务器中,我可以使用以下属性进行设置:
In WebLogic server, I am able to set using following properties:
oracle.jdbc.ReadTimeout=50000
oracle.net.CONNECT_TIMEOUT=20000
推荐答案
您可以将其设置为:
@Bean
public HikariDataSource dataSource() {
HikariDataSource ds = new HikariDataSource();
ds.setDriverClassName(springDatasourceDriverClassName);
ds.setJdbcUrl(springDatasourceUrl);
ds.setUsername(springDatasourceUsername);
ds.setPassword(springDatasourcePassword);
ds.setDataSourceProperties(oracleProperties());
return ds;
}
Properties oracleProperties() {
Properties properties = new Properties();
properties.put("oracle.net.CONNECT_TIMEOUT", 10000);
properties.put("oracle.net.READ_TIMEOUT", 10000);
properties.put("oracle.jdbc.ReadTimeout", 10000);
return properties;
}
如果不想为DataSource配置Bean(大多数人会这样做),则可以在application.properties中配置网络超时属性:
And if you do not want to configure a bean for the DataSource(which is what most people will do), you can configure the network timeout properties in application.properties:
spring.datasource.hikari.data-source-properties.oracle.net.CONNECT_TIMEOUT=10000
spring.datasource.hikari.data-source-properties.oracle.net.READ_TIMEOUT=10000
spring.datasource.hikari.data-source-properties.oracle.jdbc.ReadTimeout=10000
这篇关于如何在Spring Boot应用程序中设置Oracle数据库连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文