【问题标题】:Using Spring Cloud Connectors together with HikariCP将 Spring Cloud 连接器与 HikariCP 一起使用
【发布时间】:2015-08-05 16:44:06
【问题描述】:

我想使用 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.

来自日志输出。

edit 2:HikariCP在classpath里,好像tomcat高性能连接池也在classpath里。

【问题讨论】:

    标签: spring hikaricp spring-cloud-connectors


    【解决方案1】:

    正如我在第二次编辑中所述,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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      相关资源
      最近更新 更多