问题描述
我正在尝试创建一个 Spring Boot 应用程序,该应用程序将一些数据插入到 GCP MysqL 中。但是每次我尝试运行应用程序时,它都会显示异常 -
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
请帮忙。提前致谢
解决方法
在 CLI 上运行以下命令:
gcloud auth application-default login