Zenny
Zenny

Reputation: 89

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. enter image description here

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

Upvotes: 0

Views: 502

Answers (2)

Nibrass H
Nibrass H

Reputation: 2487

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.

Upvotes: 1

marian.vladoi
marian.vladoi

Reputation: 8066

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

Upvotes: 1

Related Questions