Micronaut 数据 MySQL 数据库连接自动重新连接不工作

Micronaut Data MySQL database connection autoreconnect not working

我有以下 MySQL 数据库的连接字符串。它在启动期间工作正常,经过一些空闲时间 MySQL 连接因未重新连接而断开。

我们需要包含哪些其他属性来保持连接有效?

datasources:
  default:
    url:  ${JDBC_URL:`jdbc:mysql://dbhost/DB?autoReconnect=true`}
    driverClassName: com.mysql.cj.jdbc.Driver
    username: ${JDBC_USER}
    password: ${JDBC_PASSWORD}        
    dialect: MYSQL

错误

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: The last packet successfully received from the server was 41,608,139 milliseconds ago. The last packet sent successfully to the
server was 41,608,144 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

我在我的项目中包含 tomcat 个 jar。

compileOnly "io.micronaut.data:micronaut-data-processor:$micronautDataVersion"
implementation "jakarta.persistence:jakarta.persistence-api:2.2.2"
implementation "io.micronaut.data:micronaut-data-jdbc:$micronautDataVersion" 
implementation "io.micronaut.configuration:micronaut-jdbc-tomcat"

我添加了这些 settings.It 保持连接。

datasources:
  default:
    pooled: true
    jmxExport: true
    url:  ${JDBC_URL:`jdbc:mysql://dbhost/DB?autoReconnect=true`}
    driverClassName: com.mysql.cj.jdbc.Driver
    username: ${JDBC_USER}
    password: ${JDBC_PASSWORD}            
    dialect: MYSQL
    jmxEnabled: true
    initialSize: 5
    maxActive: 50
    minIdle: 5
    maxIdle: 25
    maxWait: 10000
    maxAge: 600000
    timeBetweenEvictionRunsMillis: 5000
    minEvictableIdleTimeMillis: 60000
    validationQuery: "SELECT 1"
    validationQueryTimeout: 3
    validationInterval: 15000
    testOnBorrow: true
    testWhileIdle: true
    testOnReturn: false
    jdbcInterceptors: "ConnectionState;StatementCache(max=200)"