【问题标题】:Connect Java spring project with cloud database将Java Spring项目与云数据库连接
【发布时间】:2019-10-08 17:08:09
【问题描述】:

我在 Java 中创建了一个 Spring Boot 项目,它与我的本地数据库完美配合,但我无法将它连接到我的 GCP postgres 云 SQL 实例。

我已按照以下步骤操作:https://cloud.spring.io/spring-cloud-gcp/multi/multi__spring_jdbc.html 我还在 pom.xml 中做了必要的更改。 我需要在 application.properties 文件中更改什么吗?

spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.initialization-mode=always
spring.datasource.initialize=true
spring.datasource.schema=classpath:/schema.sql
spring.datasource.continue-on-error=true

我希望我的项目能够正常运行,指向云数据库。

【问题讨论】:

  • 请提供您现在面临的错误。您可能在日志中有异常,并带有与数据库相关的错误消息。如果我们一开始就有这个错误,那么找出问题所在会更容易。

标签: java postgresql maven spring-cloud-gcp


【解决方案1】:

取决于您使用的云。

您创建的数据库有端点。

您必须放置该端点链接而不是 Localhost。spring.datasource.url=jdbc:postgresql://(put your end point here instead of localhost):5432/postgres

确保您的数据库名称应与链接中的相同。

如果你在那里使用Spring,那么你应该首先创建数据库开发环境。

除了在 Pom.xml 中你需要添加云的依赖。

如果您想访问该数据库,那么您必须使用 JackDB 平台。

感谢和问候,

JerryRank

【讨论】:

  • 谢谢。您能否帮我在 pom.xml 中添加什么依赖项。
  • com.google.cloud.sqlmysql-socket-factory-connector-j-61.0.12 如果您使用 GCP,则需要添加此依赖项并检查 google 插件。
猜你喜欢
  • 2016-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-14
  • 1970-01-01
  • 1970-01-01
  • 2018-07-28
相关资源
最近更新 更多