【问题标题】:连接到 Cloud SQL 失败
【发布时间】:2020-08-27 13:50:25
【问题描述】:

我正在尝试使用具有云编辑器角色的服务帐户连接到 GCP 云 sql。我正在按照此处给出的示例进行操作

Spring cloud GCP postgres example using service account

我的 application.properties 文件

    # 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

我遇到了凭据错误

 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;

【问题讨论】:

    标签: spring-boot google-cloud-platform google-cloud-sql spring-cloud-gcp


    【解决方案1】:

    基于此link 我认为不是:

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

    你应该使用:

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

    【讨论】:

    猜你喜欢
    • 2023-03-18
    • 2021-10-24
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 2015-10-23
    相关资源
    最近更新 更多