Search code examples
springhikaricpspring-cloud-connectors

Using Spring Cloud Connectors together with HikariCP


I would like to use HikariCP from the Spring Cloud Connectors. I am not sure how to proceed...

I have updated my Spring Cloud Connectors to 1.2.0.RC1.

Here is my current config:

@Configuration
@Profile({ Profiles.CLOUD })
public class CloudDataSourceConfiguration extends AbstractCloudConfig {

    @Bean
    public DataSource dataSource() {
        int dbcpMaxActive = 10;
        int dbcpMaxWait = 200;
        PoolConfig poolConfig = new PoolConfig(dbcpMaxActive, dbcpMaxWait);
        ConnectionConfig connectionConfig = new ConnectionConfig("sessionVariables=sql_mode='ANSI';characterEncoding=UTF-8");
        DataSourceConfig serviceConfig = new DataSourceConfig(poolConfig, connectionConfig);
        return connectionFactory().dataSource("CLEARDB_DATABASE", serviceConfig);
    }
}

Can someone please advise?

edit: When I start the app with the cloud profile, I can read

 2015-05-23 22:46:56,029 [localhost-startStop-1] INFO  org.springframework.cloud.service.relational.PooledDataSourceCreator - Found Tomcat high-performance connection pool on the classpath. Using it for DataSource connection pooling.

from the log output.

edit 2: HikariCP is in the classpath and it seems that tomcat high performance connection pool is also in the classpath.


Solution

  • As stated in my second edit, both tomcat jdbc & HikariCP were on the classpath. By removing tomcat jdbc as follows (in my gradle script):

    compile("org.springframework.boot:spring-boot-starter-data-jpa"){
                exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
            }
    

    only HikariCP remained on the classpath and it was picked up properly as shown by the log output below:

    INFO  org.springframework.cloud.service.relational.PooledDataSourceCreator - Found HikariCP on the classpath. Using it for DataSource connection pooling.