无法从谷歌应用引擎连接谷歌云sql

时间:2018-05-10 07:43:10

标签: google-app-engine google-cloud-sql

无法从谷歌应用引擎

连接谷歌云sql

越来越 logMessage:" [

j~gcp-ws-203608/20180510t123822.409615356828549281].<stdout>: 2018-05-10 07:20:08.036 ERROR 1 --- [Request5396402F] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_112-google-v7]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_112-google-v7]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_112-google-v7]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_112-google-v7]
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[jdbc-mysql-connector.jar:na]
    at com.mysql.jdbc.Util.getInstance(Util.java:386) ~[jdbc-mysql-connector.jar:na]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1014) ~[jdbc-mysql-connector.jar:na]

使用依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> 

<dependency>
  <groupId>com.google.cloud.sql</groupId>
  <artifactId>mysql-socket-factory-connector-j-6</artifactId>
  <version>1.0.5</version>
</dependency>

1 个答案:

答案 0 :(得分:0)

似乎设置与数据库的连接的方式可能有问题。 请确保:

  • 设置从App Engine访问Cloud SQL的正确服务帐户(如果App Engine应用程序和Cloud SQL实例位于不同的Google Cloud Platform项目中)
  • 您已在Cloud SQL中创建了一个数据库
  • 您已将所有正确的参数值(Cloud SQL实例连接名称,数据库,用户和密码)添加到pom.xml文件中。
  • 您正在创建连接URL并建立与数据库的连接,方法与在this example
  • 中完成相同