0

我想使用 Spring Cloud Connectors 中的 HikariCP。我不知道如何继续...

我已将 Spring Cloud 连接器更新为 1.2.0.RC1。

这是我当前的配置:

@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);
    }
}

有人可以建议吗?

编辑:当我使用云配置文件启动应用程序时,我可以阅读

 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.

从日志输出。

编辑 2:HikariCP 在类路径中,似乎 tomcat 高性能连接池也在类路径中。

4

1 回答 1

3

正如我在第二次编辑中所述,tomcat jdbc 和 HikariCP 都在类路径中。通过如下删除tomcat jdbc(在我的gradle脚本中):

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

只有 HikariCP 保留在类路径上,并且它被正确拾取,如下面的日志输出所示:

INFO  org.springframework.cloud.service.relational.PooledDataSourceCreator - Found HikariCP on the classpath. Using it for DataSource connection pooling.
于 2015-05-23T21:28:21.133 回答