我在 App Engine 上部署了一個 SpringBoot 應用程式,我的資料庫是 MySQL 8。對于我的本地測驗,我可以使用公共 IP 連接到 Cloud DB,并且連接作業正常。
但是當這個應用程式部署在 App Engine 上時,我收到錯誤:
2021-11-09 01:44:50 default[1] 2021-11-09 01:44:50.874 INFO 10 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.25.Final
2021-11-09 01:44:51 default[1] 2021-11-09 01:44:51.092 INFO 10 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-11-09 01:46:58 default[1] 2021-11-09 01:46:58.343 WARN 10 --- [ main] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata
2021-11-09 01:46:58 default[1]
2021-11-09 01:46:58 default[1] com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
2021-11-09 01:46:58 default[1]
2021-11-09 01:46:58 default[1] The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
2021-11-09 01:46:58 default[1] at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.26.jar!/:8.0.26]
2021-11-09 01:46:58 default[1] at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.26.jar!/:8.0.26]
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.net.ConnectException: Connection timed out (Connection timed out)
我已按照檔案中提到的步驟操作:https : //cloud.google.com/sql/docs/mysql/connect-app-engine-standard
應用程式.yaml
runtime: java11
instance_class: F2
entrypoint: java -noverify -jar strategy-0.0.1-SNAPSHOT.war
應用程式屬性
#spring.datasource.url=jdbc:mysql://35.345.11.132:3306/fin_strat
spring.datasource.url=jdbc:mysql://localhost:3306/fin_strat
spring.datasource.username=<database-user-name>
spring.datasource.password=<database-password>
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
從 App Engine 連接時,我不確定我錯過了什么。請協助。
uj5u.com熱心網友回復:
當您使用 App ENgine(或 Cloud Functions 或 Cloud Run)中的 Cloud SQL 功能連接您的 Cloud SQL 資料庫時,該服務會打開一個套接字來連接資料庫。您不必使用公共 IP,而是使用打開的 soket。
它類似于套接字模式下的 Cloud SQL 代理。您在此處有包含 Java 示例的檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/361602.html
上一篇:如何解決ModuleNotFoundError:在GAE標準中匯入automl時沒有名為“google.cloud”的模塊?
