【问题标题】:Hikari throws an error Property url does not exist on target class org.postgresql.ds.PGPoolingDataSourceHikari 抛出错误 目标类 org.postgresql.ds.PGPoolingDataSource 上不存在属性 url
【发布时间】:2019-02-02 15:58:10
【问题描述】:

我正面临来自 kubernetes 集群的这个错误。虽然它可以在我的本地服务器上完美运行。这是我的SpringBoot App的application.yml

春天:

datasource:
    dataSourceClassName: org.postgresql.ds.PGPoolingDataSource
    url: jdbc:postgresql://${POSTGRES_HOST}:5432/test_db
    databaseName: test_db
    poolName: SpringBootHikariCP
    username: ${POSTGRES_USER}
    password: ${POSTGRES_PASSWORD}
    testWhileIdle: true
    validationQuery: SELECT 1
jpa:
    database-platform: org.hibernate.dialect.PostgreSQL82Dialect
    openInView: false
    show_sql: true
    generate-ddl: true
    hibernate:
        ddl-auto: update
        naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
        use-new-id-generator-mappings: true
    properties:
        hibernate.cache.use_second_levelt_cache: false
        hibernate.cache.use_query_cache: false
        hibernate.generate_statistics: true
        hibernate.hbm2ddl.auto: validate

这是我的 Hikari 配置。

            HikariConfig config = new HikariConfig();
            config.setDataSourceClassName(dataSourceClassName);
            config.addDataSourceProperty("url", url);
            config.addDataSourceProperty("user", user);
            config.addDataSourceProperty("password", password);

            return new HikariDataSource(config);

我已经检查了没有 Hikari 的 kubernetes 的数据库连接,它运行良好。所以连接没有问题。 请帮我解决这个问题。我坚持了几天。 谢谢

【问题讨论】:

    标签: java postgresql spring-boot kubernetes hikaricp


    【解决方案1】:

    ${POSTGRES_HOST} 期待您在特定机器中可能缺少的 system environment variable,例如添加它:

    export POSTGRES_HOST="1.1.1.1"
    

    【讨论】:

    • 不幸的是,环境变量没有问题。我可以看到应用程序可以从环境变量中获取信息。例如 url 生成像 jdbc:postgresql://postgres:5432/postgres 。不知道当我将连接到 hikaricp 配置到 kubernetes 时会发生什么。谢谢
    • @shawon 你检查到主机/IP 的连接了吗?
    • 是的,我可以连接到主机。
    • @shawon 你能改成使用IP吗?
    • 尊敬的@user7294900 此服务器位于 kubernetes 集群中。它通常与 IP 地址一起使用。
    【解决方案2】:

    url 更改为jdbc:postgresql://localhost:5432/test_db

    jdbc:postgresql://<host ip>:5432/test_db
    

    看起来占位符${POSTGRES_HOST}有问题

    尝试使用本地主机

    datasource:
        dataSourceClassName: org.postgresql.ds.PGPoolingDataSource
        url: jdbc:postgresql://localhost:5432/test_db;
        databaseName: test_db
        poolName: SpringBootHikariCP
        username: ${POSTGRES_USER}
        password: ${POSTGRES_PASSWORD}
        testWhileIdle: true
        validationQuery: SELECT 1
    

    可能是你没有设置环境变量${POSTGRES_HOST},这也是一个原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 2016-08-27
      • 1970-01-01
      • 2018-11-13
      • 2016-09-07
      相关资源
      最近更新 更多