简体   繁体   中英

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. 在此处输入图片说明

Below I have attached code from 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

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-gcp-starter</artifactId>
</dependency>

In cloud sql default configuration I have used to create database. Whenever I fire this command I am getting this error.

mvn -DskipTests package 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.

Here is a Codelabs tutorial which you can follow to set private IP for your SQL instance.

I followed this tutorial for Spring Application. Spring Pet Clinic using Cloud SQL

One difference that I noticed was in 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 :

     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

EDIT:

I was able to Deploy Spring Boot Application (Pet Clinic) on App Engine standard. Here you can find my pom.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM