【问题标题】:Google APP Engine and cloud sql :: Unable to connect Spring boot app in Google cloud sql (my sql)Google APP Engine和cloud sql :: Unable to connect Spring boot app in Google cloud sql (my sql)
【发布时间】:2019-12-18 05:08:01
【问题描述】:

我在谷歌云 sql 的 APP 引擎中连接我的 Spring Boot APP 时收到此错误。

下面我附上了来自 application.properties 的代码

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://google/myprojectID?cloudSqlInstance=myInstance:us-central1:my-sql-instance&socketFactory=com.google.cloud.sql.mysql.SocketFactory
spring.datasource.username=root
spring.datasource.password=myPassword

pom.xml

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-gcp-starter</artifactId>
</dependency>

在云 sql 默认配置中,我使用了创建数据库。 每当我触发此命令时,我都会收到此错误。

mvn -DskipTests package appengine:deploy

【问题讨论】:

    标签: java mysql spring-boot google-app-engine google-cloud-sql


    【解决方案1】:

    根据作为解决方案的@zenny 的评论,为了解决这个问题,您必须在您的SQL instance 中设置私有 IP,并将该私有 IP 用于您的数据库本地 url。

    Here 是一个 Codelabs 教程,您可以按照该教程为您的 SQL 实例设置私有 IP。

    【讨论】:

      【解决方案2】:

      我按照本教程学习了 Spring 应用程序。 Spring Pet Clinic using Cloud SQL

      我注意到的一个区别是在 pom.xml 中:

           ```<!-- Add CloudSQL Starter for MySQL -->
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-gcp-starter-sql-mysql</artifactId>
        </dependency>
      

      也在Spring Cloud GCP:

           SQL - MySQL
      
           Cloud SQL integrations with MySQL
      
           org.springframework.cloud:spring-cloud-gcp-starter-sql-mysql
      

      您可以找到更多信息Spring Cloud GCP MySQL Sample

      编辑:

      我能够在 App Engine 标准上部署 Spring Boot 应用程序(宠物诊所)。在这里你可以找到我的pom.xml

      【讨论】:

      • 你用的是标准的APP Engine还是本地的tomcat?我也使用了您给出的链接示例,但它对我不起作用。
      • 我正在使用 Tomcat 并且正在工作,我必须在 application.properties 文件中添加 spring.cloud.gcp.sql.database-name=
      • 嘿@Zenny,这个解决方案对你有用吗?如果是这样,请不要忘记将此答案标记为已接受并对其进行投票以提高其他社区用户的可见性。否则,请指出您目前面临的问题,我会尽力帮助您。
      • @sllopis 不,这个解决方案对我不起作用。我已经在我的 GCP sql 实例中设置了私有 IP,并在我的数据库本地 url 中使用了该 IP。现在正在发挥作用。
      • 嗨@Zenny,你能写出你的解决方案作为答案吗?它可以帮助遇到相同或类似问题的其他用户了解您是如何解决的。
      猜你喜欢
      • 1970-01-01
      • 2013-06-06
      • 2015-12-18
      • 1970-01-01
      • 2020-06-26
      • 2014-08-03
      • 2014-05-28
      • 2014-04-10
      • 2014-07-19
      相关资源
      最近更新 更多