0

在 WildFly 独立配置中,我们可以在数据源中定义验证查询。如果数据库连接丢失,在定义的后台验证毫秒后,可以恢复连接。如果连接丢失,则如果没有此验证,则在重新启动应用程序之前无法恢复。

    <datasource jndi-name="java:jboss/datasources/MyDS" pool-name="MyDS" enabled="true" use-java-context="true">
        <connection-url>jdbc:postgresql://localhost:5432/myDB</connection-url>
        <driver>postgresql</driver>
        <security>
            <user-name>dbuser</user-name>
            <password>password</password>
        </security>
        <validation>
            <check-valid-connection-sql>select 1</check-valid-connection-sql>
            <validate-on-match>false</validate-on-match>
            <background-validation>true</background-validation>
            <background-validation-millis>30000</background-validation-millis>
        </validation>
    </datasource>

如何在 Thorntail project.yml 文件中实现相同的目标?

thorntail:
  datasources:
    data-sources:
      MyDS:
        driver-name: postgresql
        connection-url: jdbc:postgresql://localhost:5432/myDB
        user-name: dbuser
        password: password

我尝试添加一个验证节点,但它不起作用

      validation:
        check-valid-connection-sql: select 1
        validate-on-match: false
        background-validation: true
        background-validation-millis: 30000
4

1 回答 1

1

这是一个取自本文档的示例 PostgreSQL 数据源:https ://docs.thorntail.io/2.7.0.Final/#_example_datasource_definitions它也包括连接验证。

thorntail:
  datasources:
    data-sources:
      MyDS:
        driver-name: postgresql
        connection-url: jdbc:postgresql://localhost:5432/postgresdb
        user-name: admin
        password: admin
        valid-connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker
        validate-on-match: true
        background-validation: false
        exception-sorter-class-name: org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter

其他连接验证选项(包括您使用的选项)在同一文档中进行了描述。

于 2020-08-26T11:07:43.707 回答