Custom datasource is not using the hikari configuration from the property file and using the default configuration.

Config:

spring:
    profiles:
        active: "dev"
    datasource:
        hikari:
            maxLifetime: 30000
            maximumPoolSize: 1
            idleTimeout: 10000
            poolName: IPDS-DB-POOL-1

Logs

**maximumPoolSize.................10**
metricRegistry..................none
metricsTrackerFactory...........none
minimumIdle.....................10
password........................<masked>
**poolName........................"HikariPool-1"**
readOnly........................false
registerMbeans..................false
scheduledExecutor...............none
schema..........................none
threadFactory...................internal
transactionIsolation............default

Comment From: wilkinsona

Can you please expand a bit on what you mean by a “custom DataSource”? If you have defined your own DataSource bean, it will only use the configuration properties if you’ve configured it to do so.

If you’d like is to spend some time investigating, please spend some time to provide a minimal example that reproduces the problem You can share it with us in a separate repository on GitHub or as a zip file attached to this issue.

Comment From: sohailashraf003

Let me explain more.

I have configured a custom datasource configuration class in springboot and added a few config properties for hikari in configuration file as you can see in the above example.

when I run the application below dataSource class spring boot is using the default properties for hikari and ignoring the properties which are defined in the config file.

But When I removed the custom datasource class and run the application, I can see the the custom properties which are defined in the property file are reflecting in the logs.

Example:

@Configuration
public class DataSourceConfig extends HikariConfig  {

    @Autowired
    private SecureCipher secureCipher;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;
    @Value("${spring.datasource.driverClassName}")
    private String driverClassName;
    @Value("${spring.datasource.dbname}")
    private String dbname;
    @Value("${spring.datasource.url}")
    private String url;

    @Bean
    public DataSource getDataSource() {
        Optional<String> decryptedPassword = secureCipher.decrypt(password);
        if(!decryptedPassword.isPresent())
            throw new NullPointerException("Failed to initialized data source. Error in decrypting password");

        DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
        dataSourceBuilder.driverClassName(driverClassName);
        dataSourceBuilder.url(url);
        dataSourceBuilder.username(username);
        dataSourceBuilder.password(decryptedPassword.get());
        return dataSourceBuilder.build();
    }
}

As of now application has only this class and nothing much, so you can just create a Springboot application and add this class, you should able to reproduce with this setup.

Comment From: snicoll

@sohailashraf003 this is working as expected. if you're creating the DataSource bean yourself, the auto-configuration backs off. If it backs off, none of the standard properties binding occurs.

There are some examples in the reference documentation about creating a custom datasource. You should rather decypt the password in an EnvironmentPostProcessor and let the auto-configuration do its job.

Please follow-up on StackOverflow if you have more questions, as mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.