Darshil Gada
Darshil Gada

Reputation: 95

How do I configure HikariCP in my Spring Boot app in my applicationContext files?

I am trying to configure HikariCP in my SpringBoot application. But its not working. Attaching code snippets. Any help will be appreciated.

<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
    <property name="dataSourceClassName" value="oracle.jdbc.driver.OracleDataSource" />
    <property name="maximumPoolSize" value="50" />
    <property name="idleTimeout" value="240" />

    <property name="dataSourceProperties">
        <props>
            <prop key="url">${javax.persistence.jdbc.url}</prop>
            <prop key="user">${javax.persistence.jdbc.user}</prop>
            <prop key="password">${javax.persistence.jdbc.password}</prop>
        </props>
    </property>
</bean> 

<!-- HikariCP configuration -->
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource"
    destroy-method="close">
    <constructor-arg ref="hikariConfig" />
</bean>

Upvotes: 0

Views: 633

Answers (1)

Prashant Goswami
Prashant Goswami

Reputation: 175

In your case, HikariCP will be configured by default so you just need to configure the following optional properties related to hikari as below:

spring.datasource.url=jdbc:mysql://localhost:3306/{databasename}
spring.datasource.username={user}
spring.datasource.password={password}

spring.datasource.hikari.maximum-pool-size=12
spring.datasource.hikari.idle-timeout=300000

Upvotes: 1

Related Questions