[英]Google APP Engine and cloud sql :: Unable to connect Spring boot app in Google cloud sql (my sql)
I am getting this error while connecting my Spring boot APP inside APP engine in Google cloud sql.在 Google Cloud sql 中的 APP 引擎内连接我的 Spring Boot APP 时出现此错误。
Below I have attached code from application.properties下面我附上了 application.properties 中的代码
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://google/myprojectID?cloudSqlInstance=myInstance:us-central1:my-sql-instance&socketFactory=com.google.cloud.sql.mysql.SocketFactory
spring.datasource.username=root
spring.datasource.password=myPassword
pom.xml pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter</artifactId>
</dependency>
In cloud sql default configuration I have used to create database.在云 sql 默认配置中,我用来创建数据库。 Whenever I fire this command I am getting this error.每当我触发此命令时,我都会收到此错误。
mvn -DskipTests package appengine:deploy mvn -DskipTests 包 appengine:deploy
Based on the @zenny's comment that served as a solution, In order to solve the issue, you've to set private IP in your SQL instance and use that private IP for your database local url.根据作为解决方案的@zenny 的评论,为了解决该问题,您必须在SQL 实例中设置私有 IP,并将该私有 IP 用于您的数据库本地 url。
Here is a Codelabs tutorial which you can follow to set private IP for your SQL instance. 这是一个 Codelabs 教程,您可以按照该教程为 SQL 实例设置私有 IP。
I followed this tutorial for Spring Application.我遵循了 Spring Application 的本教程。 Spring Pet Clinic using Cloud SQL 使用 Cloud SQL 的 Spring Pet Clinic
One difference that I noticed was in pom.xml:我注意到的一个区别是在 pom.xml 中:
```<!-- Add CloudSQL Starter for MySQL -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-mysql</artifactId>
</dependency>
Also in Spring Cloud GCP :同样在Spring Cloud GCP 中:
SQL - MySQL
Cloud SQL integrations with MySQL
org.springframework.cloud:spring-cloud-gcp-starter-sql-mysql
You can find more information Spring Cloud GCP MySQL Sample您可以找到更多信息Spring Cloud GCP MySQL 示例
I was able to Deploy Spring Boot Application (Pet Clinic) on App Engine standard.我能够在 App Engine 标准上部署 Spring Boot 应用程序(宠物诊所)。 Here you can find my pom.xml在这里你可以找到我的pom.xml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.