【问题标题】:How to confgure the PGProperty TCP_KEEP_ALIVE that is available at HikariConfig如何配置 HikariConfig 提供的属性 TCP KEEP_ALIVE
【发布时间】:2021-04-20 10:26:17
【问题描述】:

如何配置tcpkeepalive值设置为true的属性值?

我已经试过了

spring:
  datasource:
    connection-properties: tcpKeepAlive=true
    connectionproperties: tcpKeepAlive=true

但是,没有成功。

HikariConfig 确实包含一个 Properties 对象,但是这些值是如何在加载它们的 yml 文件中定义的?

【问题讨论】:

    标签: java spring postgresql spring-boot hikaricp


    【解决方案1】:

    假设该属性是驱动的连接属性,则需要在hikari上配置dataSourceProperties属性。你可以这样做:

    spring:
      datasource:
        hikari:
          data-source-properties:
            tcpKeepAlive: true
    

    或者,您可以将属性包含在 spring.datasource.url 属性中。

    【讨论】:

    • 谢谢,您的第一个建议已经奏效。我也尝试了 url 属性,但没有奏效。 “url:jdbc:postgresql://localhost:5430/postgres;tcpKeepAlive=true”的格式对吗?
    • @sge 不,应该是jdbc:postgresql://localhost:5430/postgres?tcpKeepAlive=true,另见jdbc.postgresql.org/documentation/head/connect.html
    • 它也适用于 url 参数(yaml 属性和 url 属性不能混合)。网址:jdbc:postgresql://localhost:5430/postgres?username=postgres&password=postgres&tcpKeepAlive=true
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多