我有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
srcmainappengineapp.yaml
中的应用引擎配置
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
中的应用引擎服务帐号角色:
Cloud SQL Admin
Cloud SQL Client
Cloud SQL Editor
Cloud SQL Instance User
Editor
Cloud Run Admin
可能有任何遗漏或未配置的内容?
我遵循Google Cloud Community关于将Grails应用程序部署到app Engine灵活环境的文档。如果您仍然无法使用云SQL的IP地址连接,请尝试使用dataSource
的url
中的云SQL实例的实例连接名称和build.gradle
中的其他MYSQL依赖项:
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]
,使用您的实例名,它在您的云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'