0

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;
adorearun
  • 151
  • 1
  • 13

1 Answers1

0

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
irvifa
  • 1,865
  • 2
  • 16
  • 20
  • @adorearun can you confirm this... this is quite confusing as the `README.adoc` is saying to just uncomment, but it seems the property should be changed as well.... – vitooh May 12 '20 at 16:04
  • Yes uncomment and add the file location , changing like above answer also didnt do the trick. – adorearun May 13 '20 at 01:29
  • Any luck with this issue? https://github.com/spring-cloud/spring-cloud-gcp/issues/1679 – irvifa May 13 '20 at 19:51
  • Another way to do that is passing base64 encoded sttring mentioned in https://docs.spring.io/spring-cloud-gcp/docs/1.0.0.BUILD-SNAPSHOT/reference/htmlsingle/ `spring.cloud.gcp.credentials.encoded-key` – irvifa May 13 '20 at 19:52