将 Java spring 项目与云数据库连接
Connect Java spring project with cloud database
我在 Java 中创建了一个 spring 引导项目,它与我的本地数据库完美配合,但我无法将它连接到我的 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
我希望我的项目能够正常运行,指向云数据库。
取决于您使用的是哪种云。
您创建的数据库有端点。
您必须输入该端点 link 而不是本地主机。spring.datasource.url=jdbc:postgresql://(put your end point here instead of localhost):5432/postgres
确保您的数据库名称应与 link 中的相同。
如果你在那里使用Spring那么你应该首先创建数据库开发环境。
除了Pom.xml你需要添加云的依赖。
如果你想访问那个数据库,那么你必须去 JackDB 平台。
感谢和问候,
JerryRank
我在 Java 中创建了一个 spring 引导项目,它与我的本地数据库完美配合,但我无法将它连接到我的 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
我希望我的项目能够正常运行,指向云数据库。
取决于您使用的是哪种云。
您创建的数据库有端点。
您必须输入该端点 link 而不是本地主机。spring.datasource.url=jdbc:postgresql://(put your end point here instead of localhost):5432/postgres
确保您的数据库名称应与 link 中的相同。
如果你在那里使用Spring那么你应该首先创建数据库开发环境。
除了Pom.xml你需要添加云的依赖。
如果你想访问那个数据库,那么你必须去 JackDB 平台。
感谢和问候,
JerryRank