If your Spring Boot application is ignoring HikariCP configuration, there could be a few reasons for this behavior. Here are some steps you can take to troubleshoot and resolve the issue:
Ensure that you are using the correct property names for configuring HikariCP in your application.properties or application.yml file. For HikariCP, properties typically start with spring.datasource.
Example application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase spring.datasource.username=username spring.datasource.password=password spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.hikari.maximum-pool-size=10
Double-check your configuration to ensure that it is being loaded correctly. You can enable debug logging for Spring Boot to see which properties are being applied. Add the following line to your application.properties file:
logging.level.org.springframework.boot.autoconfigure.logging=DEBUG
Check for dependency conflicts in your project. Ensure that you don't have conflicting versions of HikariCP or any other database connection pooling libraries in your classpath. Spring Boot typically manages dependencies for you, but it's worth verifying.
If you have a custom configuration class for the data source, ensure that it is correctly annotated and registered with Spring Boot.
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.jdbc.DataSourceBuilder; import javax.sql.DataSource; @Configuration public class DataSourceConfiguration { @Bean public DataSource dataSource(DataSourceProperties properties) { return DataSourceBuilder.create() .url(properties.getUrl()) .username(properties.getUsername()) .password(properties.getPassword()) .build(); } } If you are explicitly creating a DataSource bean, make sure that your custom bean is not conflicting with the auto-configured DataSource bean provided by Spring Boot.
Ensure that you don't have any properties or beans that override the HikariCP configuration. Spring Boot allows properties to be overridden using environment variables, system properties, or configuration files.
If you are using profiles, verify that your HikariCP configuration is not profile-specific and is applied to all profiles that you are using.
By following these steps, you should be able to identify and resolve the issue with your HikariCP configuration in your Spring Boot application.
Spring Boot HikariCP configuration properties
Description: Configuring HikariCP connection pool properties in Spring Boot application.
spring: datasource: url: jdbc:mysql://localhost:3306/mydb username: root password: password driver-class-name: com.mysql.cj.jdbc.Driver hikari: maximum-pool-size: 10 minimum-idle: 5
maximum-pool-size and minimum-idle are HikariCP specific configuration options.Spring Boot HikariCP not using maxLifetime
Description: Troubleshooting why HikariCP's maxLifetime property is not being applied.
spring: datasource: hikari: max-lifetime: 1800000 # 30 minutes in milliseconds
max-lifetime is correctly configured in the Spring Boot application properties file (application.yml or application.properties). This property specifies the maximum lifetime of a connection in the pool.Spring Boot HikariCP connection timeout not working
Description: Fixing issues with HikariCP connection timeout configuration in Spring Boot.
spring: datasource: hikari: connection-timeout: 30000 # 30 seconds in milliseconds
connection-timeout property to set the maximum time that a client (application) will wait for a connection from the pool.Spring Boot HikariCP idleTimeout ignored
Description: Addressing why idleTimeout setting for HikariCP is not taking effect.
spring: datasource: hikari: idle-timeout: 600000 # 10 minutes in milliseconds
idle-timeout is correctly configured to specify the maximum time that a connection is allowed to sit idle in the pool before being closed.Spring Boot HikariCP pool properties not applied
Description: Ensuring that custom HikariCP pool properties are applied correctly in Spring Boot.
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.sql.DataSource; @Configuration public class DataSourceConfig { @Bean @Autowired public DataSource dataSource() { return DataSourceBuilder.create() .url("jdbc:mysql://localhost:3306/mydb") .username("root") .password("password") .type(com.zaxxer.hikari.HikariDataSource.class) .build(); } } DataSourceBuilder and specifies HikariCP as the connection pool implementation (type(com.zaxxer.hikari.HikariDataSource.class)).Spring Boot HikariCP pool properties programmatically
Description: Programmatically configuring HikariCP pool properties in Spring Boot.
import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.sql.DataSource; @Configuration public class DataSourceConfig { @Bean public DataSource dataSource(DataSourceProperties properties, @Value("${spring.datasource.hikari.maximum-pool-size}") int maxPoolSize, @Value("${spring.datasource.hikari.minimum-idle}") int minIdle) { properties.setDriverClassName("com.mysql.cj.jdbc.Driver"); properties.setUrl("jdbc:mysql://localhost:3306/mydb"); properties.setUsername("root"); properties.setPassword("password"); HikariDataSource dataSource = (HikariDataSource) properties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); dataSource.setMaximumPoolSize(maxPoolSize); dataSource.setMinimumIdle(minIdle); return dataSource; } } DataSourceProperties and @Value annotations for maximum pool size and minimum idle connections.Spring Boot HikariCP connection pool logging
Description: Enabling logging for HikariCP connection pool to troubleshoot configuration issues.
logging: level: com.zaxxer.hikari: DEBUG
com.zaxxer.hikari to DEBUG in application.yml or application.properties to get detailed logs from HikariCP, which can help diagnose configuration problems.Spring Boot HikariCP maximumPoolSize not working
Description: Fixing issues with maximumPoolSize configuration in HikariCP.
spring: datasource: hikari: maximum-pool-size: 20
maximum-pool-size is correctly configured to set the maximum number of connections that can be held in the connection pool.Spring Boot HikariCP custom configuration
Description: Providing custom HikariCP configuration in Spring Boot application.
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class DataSourceConfig { @Bean @ConfigurationProperties("spring.datasource.hikari") public DataSourceProperties dataSourceProperties() { return new DataSourceProperties(); } } @ConfigurationProperties("spring.datasource.hikari") to bind HikariCP properties from application.yml to DataSourceProperties bean.Spring Boot HikariCP properties not taking effect
Description: Troubleshooting why HikariCP properties configured in application.properties are not being applied.
spring.datasource.hikari.maximum-pool-size=15 spring.datasource.hikari.minimum-idle=5
maximum-pool-size and minimum-idle properties are correctly spelled and located in application.properties or application.yml file.eloquent mtgox ruby-on-rails-3 android-location background-service azure-functions tomcat appdelegate rhel7 azure-pipelines-build-task