无法在Spring Boot应用程序中更新Hikari数据源配置

时间:2019-03-27 14:09:03

标签: spring-boot hikaricp

Hikari数据源配置始终采用默认值。即使我在application.yml文件中提供了实际配置。

MainApp.java

@SpringBootApplication
public class MainApp {

public static void main(String[] args) {
    SpringApplication.run(MainApp.class, args);
}

@Bean
@Primary
public DataSourceProperties dataSourceProperties() {
    return new DataSourceProperties();
}

//I use below method to set password from different approach instead of taking from app.yml
@Bean
public DataSource dataSource(DataSourceProperties properties) {
    DataSource ds = properties.initializeDataSourceBuilder()
     .password("setting a password from vault")
     .build();
    return ds;
}
}

application.yml

spring:
  application:
    name: demo
  datasource:
    hikari:
      connection-timeout: 20000
      minimum-idle: 5
      maximum-pool-size: 12
      idle-timeout: 300000
      max-lifetime: 1200000
      auto-commit: true
    driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
    url: jdbc:sqlserver://ip:port;databaseName=sample
    username: username

使用Spring 2.1.1.RELEASE,当我启动应用程序时,我记录了Hikari日志,并显示了所有默认值。因此,我确实在第二个bean数据源及其实际的HikariDatasource上进行了调试,除了默认值之外,其余其余均为空,并且未反映出application.yml中的给定值。如果我配置错误或做任何错误,请推荐或评论!

0 个答案:

没有答案