Grails 和 Google 应用引擎部署错误

Grails and Google app engine deployment errors

我有 Grails 3.3.11 应用程序,我正在尝试将其部署在灵活的 Google App Engine 上,但是,我遇到了一些错误,主要是由于连接到 Google cloud SQL,我做了 MySQL 5.7 实例并能够从我的 IDE 访问它,而当我在本地 运行 应用程序时,我搜索了一些针对这些错误的解决方案,但不幸的是,对我来说没有任何效果,这里是例外

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'methodValidationPostProcessor' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Unsatisfied dependency expressed through method 'methodValidationPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastoreServiceRegistry': Cannot resolve reference to bean 'hibernateDatastore' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to check JDBC Connection auto-commit in preparation for DDL execution
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
    at 

org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:46)
"

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Caused by: java.net.ConnectException: Connection timed out (Connection timed out)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:299)     

这里是application.yml

中的生产配置
dataSource:
      
        dbCreate: create-drop
        driverClassName: com.mysql.jdbc.Driver 
        dialect: org.hibernate.dialect.MySQL5Dialect
        username: myUsername
        password: myPassword
        url: jdbc:mysql://DBIP:3306/CusOrderIns 

        properties:
            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
            defaultTransactionIsolation: 2 

build.gradle

buildscript {
repositories {
    mavenLocal()
    maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
    classpath "org.grails:grails-gradle-plugin:$grailsVersion"
    classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.15.1"
    classpath "org.grails.plugins:hibernate5:${gormVersion - ".RELEASE"}"
    classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.2'
 }
}

provided "org.springframework.boot:spring-boot-starter-jetty" 
 // provided  "org.springframework.boot:spring-boot-starter-tomcat"  //commented

src\main\appengine\app.yaml

中的 App 引擎配置
runtime: java
env: flex

runtime_config:
  jdk: openjdk8
  server: jetty9

resources:
  cpu: 2
  memory_gb: 5
  disk_size_gb: 10

manual_scaling:
  instances: 1

Google IAM 中的 App 引擎服务帐户角色:

Cloud SQL Admin
Cloud SQL Client
Cloud SQL Editor
Cloud SQL Instance User
Editor
Cloud Run Admin

可能遗漏或未配置任何内容?

我正在关注这个 Google 云社区 documentation 关于将 Grails 应用程序部署到 App Engine 灵活环境。如果您仍然无法使用云 SQL 的 IP 地址进行连接,请尝试在 dataSourceurl 和其他 [=36] 中使用您的云 SQL 实例的实例连接名称=] build.gradle 中的依赖项:

application.yml

production:
    dataSource:
        dbCreate: update
        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
        driverClassName: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://google/[DATABASE_NAME]?socketFactory=com.google.cloud.sql.mysql.SocketFactory&cloudSqlInstance=[INSTANCE_NAME]&useSSL=true
        username: root
        password: password

  • 对于 [DATABASE_NAME],请使用您在创建数据库时使用的数据库名称。
  • 对于 [INSTANCE_NAME],请使用您的实例名称,该名称在您的 Cloud SQL 实例详细信息中可见。

添加于build.gradle:

runtime 'mysql:mysql-connector-java:8.0.16'
runtime 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.0.14'