简体   繁体   English

在 Spring Boot 中设置 DataSource 的属性

[英]Set properties for DataSource in Spring boot

I have multiple databases in spring boot One of the configuration for Oracle database is shown我在spring boot中有多个数据库 显示了Oracle数据库的配置之一

import javax.sql.DataSource;
 
 
 @Bean 
public DataSource getDataSource() { 
    DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create(); 
    dataSourceBuilder.username("SA"); 
    dataSourceBuilder.password(""); 
    
    return dataSourceBuilder.build(); 
}
 
@Bean("OracleTemplate")
public JdbcTemplate jdbcTemplate()
{
     return new jdbcTemplate()
}

Now i want to set following properties for the Datasource .How can i set it?现在我想为数据源设置以下属性。我该如何设置?

validationOnquery
 validationQueryTimeout
 minIdle
 maxIdle
 testWhileIdle

Instead of returning datasource directly, you can store it as:您可以将其存储为:

DataSource myDataSource = dataSourceBuilder.build();
myDataSource.minIdle = 0
myDataSource.validationQuery = 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM