HikariCP icon indicating copy to clipboard operation
HikariCP copied to clipboard

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

Open fforfabio opened this issue 9 months ago • 0 comments

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:

  • Spring Boot 2.7.17
  • HikariCP 4.0.3 (automatically imported with spring-boot-starter-data-jpa 2.7.17)
  • Java 8

fforfabio avatar Nov 22 '23 13:11 fforfabio