【发布时间】:2016-12-11 14:28:15
【问题描述】:
我正在尝试使用codebase 来测试将 Google Cloud SQL 实例与 GAE 应用程序连接起来。我能够在本地成功运行它,但它似乎也在 AppEngine 中成功部署,但是当我尝试访问 myproject.appspot.com 时,我得到了 404。
以下是我遵循的步骤(跳过成功的本地相关步骤)。
- 创建了一个项目
myproject - 创建了一个 Google Cloud SQL 第二代实例,
myproject-db - 使用密码创建了
root用户。 - 使用了 Google Cloud Console
"jdbc:google:mysql://myproject:us-central1:myproject-db/demo?user=root&password=PASSWORD;"中指示的连接字符串 -
appengine-web.xml 如下所示
<?xml version="1.0" encoding="utf-8"?> <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <application>myproject</application> <version>1</version> <threadsafe>true</threadsafe> <use-google-connector-j>true</use-google-connector-j> <system-properties> <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/> <property name="cloudsql.url" value="jdbc:google:mysql://myproject:us-central1:myproject-db/demo?user=root&password=PASSWORD;"/> <property name="cloudsql.url.dev" value="jdbc:mysql://localhost/demo?user=root&useSSL=false"/> </system-properties> </appengine-web-app> -
HibernateJPAServlet 中嵌入了以下代码 sn-p
if (System.getProperty("com.google.appengine.runtime.version") .startsWith("Google App Engine/")) { Class.forName("com.mysql.jdbc.GoogleDriver"); properties.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.GoogleDriver"); properties.put("javax.persistence.jdbc.url", System.getProperty("cloudsql.url")); } -
我已将代码从本地上传到默认 myproject 存储库
我从“开发”视图启动了 Google Cloud Platform Console。
- 成功运行
mvn clean package和mvn appengine:update。由于防火墙/代理限制,我无法从本地执行appengine:update。 - 所以,在这一点上,我的理解是,我正在为 same 项目运行一个 GAE 应用程序和 GAE Cloud SQL 实例。所以
http://myproject.appspot.com/应该托管我上传的第 8 步应用程序。但是当我访问它时会显示"404" - "The requested URL / was not found on this server."
万一问题是我们无法从 Cloud Console 部署它,那么我还有什么其他选择?我绝对不能更改网络/代理规则。
编辑
我尝试使用 mvn gcloud:run 和 mvn gcloud:deploy 从外部代理/防火墙限制运行和部署应用程序。最后它清楚地说明了"Deployed URL: [https://myproject.appspot.com]"。但是当我通过浏览器访问同一个 URL 时,同样的问题仍然存在。
编辑 2
我可以从 App Engine 信息中心看到错误跟踪。这是说
" org.hibernate.exception.JDBCConnectionException: Could not open connection
Caused by: org.hibernate.exception.JDBCConnectionException: Could not open connection
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost."
我的连接字符串是“jdbc:google:mysql://myproject:us-central1:myproject-db/demo?user=root&password=PASSWD123&”
【问题讨论】:
-
您在哪里看到这个 404 错误?在日志中?在您的浏览器中?此外,在第 8 步中,您说您成功运行了
mvn appengine:update,但是您说您无法执行appengine:update。它是哪一个?该命令是成功还是失败? -
嗨 Eric,我无法从本地执行 mvn appengine:update... 但是我可以从 Google Cloud Console 执行相同操作,但部署结束后,当我尝试访问 myproject 时.appspot.com 通过浏览器,我看到 404 错误。
标签: java hibernate maven google-app-engine google-cloud-sql