【问题标题】:java.sql.SQLNonTransientConnectionException: Could not create connection to database server- Google Cloud Platformjava.sql.SQLNonTransientConnectionException:无法创建与数据库服务器的连接 - Google Cloud Platform
【发布时间】:2021-02-06 09:49:59
【问题描述】:

我正在尝试创建一个将一些数据插入 GCP Mysql 的 Spring Boot 应用程序。但是每次我尝试运行应用程序时它都会显示异常 -

  java.sql.SQLNonTransientConnectionException: Could not create connection to database server.
Caused by: java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials

下面是我的 application.properties 文件。此处未定义实际参数-

     spring.cloud.gcp.sql.database-name=DemoDatabase
        spring.cloud.gcp.sql.instance-connection-name=xxxxxxxxxxx
        spring.datasource.initialization-mode=always
spring.cloud.gcp.credentials.location=C:/Users/utkar/Downloads/spring-boot-7208e0222fb1.json
    spring.datasource.url=jdbc:mysql://google/DemoDatabase?cloudSqlInstance=XXXXXXXXXXX&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false
        spring.datasource.username=XXXXX
        spring.datasource.password=XXXXXX

请帮忙。提前致谢

【问题讨论】:

    标签: spring spring-boot google-cloud-platform spring-data-jpa spring-data


    【解决方案1】:

    在 CLI 上运行以下命令:

    gcloud auth application-default login
    

    【讨论】:

      猜你喜欢
      • 2021-07-21
      • 2018-01-13
      • 2019-06-10
      • 2021-06-30
      • 2021-10-21
      • 2023-03-03
      • 1970-01-01
      • 2014-03-06
      相关资源
      最近更新 更多