brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
19.91k stars 2.92k forks source link

Fail to load properties file in configA = new HikariConfig(propertyFileName) #2145

Open fforfabio opened 10 months ago

fforfabio commented 10 months ago

I'm trying to create a new DataSource by importing the properties file as explain here and here.
image

I have created my dataSource.properties file and put it under the src/main/resources folder in my SpringBoot project. Then I'll perform the following operations:

private static HikariConfig configA = null;
private static HikariDataSource dsA;
// Import properties from file
configA = new HikariConfig("path\\dataSource.properties");
configA.addDataSourceProperty("cachePrepStmts", "true");
configA.addDataSourceProperty("prepStmtCacheSize", "250");
configA.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
// Create the DataSource
dsA = new HikariDataSource(configA);

But when I try to get the values I'll always have null.

My dataSource.properties is like this:

dataSource.jdbcUrl=<url>
dataSource.user=sa
dataSource.password=pwd
dataSource.driverClassName=<driver>
dataSource.poolName=poolA
dataSource.maxLifetime=500000
dataSource.maximumPoolSize=10
dataSource.minimumIdle=5
dataSource.leakDetectionThreshold=2100
dataSource.connectionTimeout=30000

So I've tried to remove the dataSource. prefix from the dataSource.properties file, like this:

jdbcUrl=<url>
username=sa // username instead of user. This last one is not found
password=pwd
driverClassName=<driver>
poolName=poolA
maxLifetime=500000
maximumPoolSize=10
minimumIdle=5
leakDetectionThreshold=2100
connectionTimeout=30000

and magically the import works and I have my DataSource correctly configured.

Is it a normal behaviour? Or the documentation is wrong?

I'm using: