java.sql.sqlnontransientconnectionexception:无法创建到数据库服务器的连接-google云平台

r6hnlfcb  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(322)

我试图创建一个spring引导应用程序,将一些数据插入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文件。这里没有定义实际的paparmeters-

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

请帮忙。提前谢谢

sz81bmfz

sz81bmfz1#

在cli上运行以下命令:

gcloud auth application-default login

相关问题