gpt4 book ai didi

java - 连接Java spring项目和云数据库

转载 作者:行者123 更新时间:2023-11-29 13:09:57 25 4
gpt4 key购买 nike

我用 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

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

最佳答案

取决于您使用的是哪种云。

您创建的数据库有端点。

您必须放置端点链接而不是本地主机。spring.datasource.url=jdbc:postgresql://(将您的端点放在此处而不是本地主机):5432/postgres

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

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

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

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

感谢和问候,

杰瑞兰克

关于java - 连接Java spring项目和云数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56252957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com