无法从App Engine flex Java上的其他项目连接到Cloud SQL

无法从App Engine flex Java上的其他项目连接到Cloud SQL

问题描述:

以下是引发的异常:

javax.servlet.ServletException: javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

稍后我也会在堆栈跟踪中获得此消息:

I also get this message later on the stack trace:

Caused by: java.lang.RuntimeException: The Google Cloud SQL API is not enabled for project [xxxxxx]. Please use the Google Developers Console to enable it: https://console.cloud.google.com/apis/api/sqladmin/overview?project=xxxxxx

当我单击控制台链接时,我可以看到Cloud SQL Api已启用,并且当数据库位于同一项目中时,代码可以正常工作.我还添加了AppEngine flexible服务帐户,该帐户在包含Cloud SQL数据库且角色为Cloud SQL Client的项目中具有App Engine flexible environment Service Agent角色.

When I click on the console link, I can see that the Cloud SQL Api is enabled and the code was working perfectly when the database was on the same project. I also added the AppEngine flexible service account that has the App Engine flexible environment Service Agent role in the project containing the Cloud SQL database with the role Cloud SQL Client.

接下来我应该尝试什么?谢谢

What should I try next ? Thanks

更新

pom.xml:

-update2不再需要该文件-

-- update2 there's no more need for that file --

在其他项目中访问Cloud SQL实例时,在源项目中启用Cloud SQL Admin API非常重要.复制错误消息中的链接,然后用其他项目ID替换项目ID.当前消息会误导您,因为它当前假设实例位于同一项目中.

When accessing a Cloud SQL instance in a different project, it's important that the Cloud SQL Admin API is enabled in the source project. Copy the link in the error message and replace the project id with the other project id. The current message is misleading as it currently assumes the instance is in the same project.