简体   繁体   中英

Connecting to Cloud SQL is failing

I am trying to connect to GCP cloud sql using service account which has cloud editor role.I am following the example given here

Spring cloud GCP postgres example using service account

my application.properties file

    # Set to the Postgres user you want to connect to; 'postgres' is the default user.
spring.datasource.username=username
spring.datasource.password=password
spring.cloud.gcp.sql.database-name=tablename
# This value is formatted in the form: [gcp-project-id]:[region]:[instance-name]
spring.cloud.gcp.sql.instance-connection-name=project-id:region:instancename
# So app starts despite "table already exists" errors.
spring.datasource.continue-on-error=true
# Enforces database initialization
spring.datasource.initialization-mode=always
spring.cloud.gcp.project-id=project-id
spring.cloud.gcp.credentials.location=file:src/main/resources/key.json

I am getting below credential error

 2020-05-11 17:10:21.494  INFO 99087 --- [nio-8085-exec-1] c.g.cloud.sql.core.CoreSocketFactory     : Connecting to Cloud SQL instance [[instance name] via SSL socket.
2020-05-11 17:10:21.494  INFO 99087 --- [nio-8085-exec-1] c.g.cloud.sql.core.CoreSocketFactory     : First Cloud SQL connection, generating RSA key pair.
2020-05-11 17:10:21.499 ERROR 99087 --- [nio-8085-exec-1] c.h.m.p.p.e.util.ExceptionManager        : Error occured

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.AbstractMethodError: org.springframework.cloud.gcp.autoconfigure.sql.SqlCredentialFactory.create()Lcom/google/api/client/http/HttpRequestInitializer;

based on this link I think instead of:

spring.cloud.gcp.credentials.location=file:src/main/resources/key.json

You should use:

spring.cloud.gcp.sql.credentials.location=file:src/main/resources/key.json

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