首页 > 解决方案 > 如何在 gcloud 应用引擎上部署两个数据库?

问题描述

我正在尝试通过 gcloud 将 Web 应用程序部署到 GCP App Engine。此 Web 应用程序使用两个不同的数据库 - 一个 DB 在“A”App Engine SQL 下,另一个 DB 在“B”App Engine SQL 下。简单地说它现在由不同的实例运行。

在 Local DB 中能够很好地运行应用程序,但是当我尝试编译我的 Java 项目时,它显示如下错误。

根据谷歌搜索,我试图找出缺少的依赖项并插入到我的 pom.xml 文件中,但它根本不起作用。

如果我将它指向本地数据库,application.properties它就能很好地编译。(do compile的目的是生成jar文件来部署我的项目。):

### *** Removed username/password and datasource url *** 

## ==============================================================
## = Datasource (Admin)
## ==============================================================
#admin.datasource.url = jdbc:mysql://localhost:3306/
admin.datasource.url = jdbc:mysql://google/url here
admin.datasource.username = 
admin.datasource.password = 
admin.datasource.driver-class-name=com.mysql.jdbc.Driver

## ==============================================================
## = Datasource 2 (API)
## ==============================================================
#api.datasource.url = jdbc:mysql://localhost:3306/
api.datasource.url = jdbc:mysql://google/url here
api.datasource.username = 
api.datasource.password = 
api.datasource.driver-class-name=com.mysql.jdbc.Driver

server.session.timeout = 600
spring.session.store-type=jdbc
server.port =8080
#server.error.whitelabel.enabled=false

我这样做时出错mvn clean install

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project WorkspezAdmin: There are test failures.
[ERROR]
[ERROR] Please refer to D:\admin_Deploy\target\surefire-reports for the individual test results.

如果我这样做mvn clean and install,我需要获取可以使用 gcloud 部署到 GCP App Engine 的 jar 文件。有没有人可以给我相关的建议?

先谢谢了。。

附加错误

 The Google Cloud SQL API is not enabled for project [workspez-admin]. Please use the Google Developers Console to enable it: https://console.cloud.google.com/apis/api/sqladmin/overview?project=workspez-admin

Error creating bean with name 'adminEntityManagerFactory' defined in class path resource [com/workspez/webconfig/AdminHibernateDbConfig.class]: Unsatisfied dependency expressed through method 'adminEntityManagerFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminDataSource' defined in class path resource [com/workspez/webconfig/AdminHibernateDbConfig.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceInitializer': Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.UncategorizedScriptException: Failed to execute database script; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: **Could not create connection to database server.**

标签: javamavengoogle-app-enginedeploymentgoogle-cloud-platform

解决方案


推荐阅读