谷歌有一个example连接云SQL-MYSQl从Spring JPA/Boot App(提交9ecdc1111e3da388a750ace41a125287d9620534被使用)。这个例子是使用Spring Data 和MySQL的工作很好。但它不工作时,配置文件被更改为postgress(后,启动正确的Postgres数据库在同一帐户和相同的步骤#2)
spring.profiles.active=postgres
并替换
<artifactId>spring-cloud-gcp-starter-sql-mysql</artifactId>
with
<artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
以及
replacing src/main/resources/application-mysql.properties
with
src/main/resources/application-postgres.properties
但应用程序仍会因
创建在类路径资源[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]中定义的名为"entityManagerFactory"的Bean时出错:调用init方法失败;嵌套异常是org. hib. service. spi。服务异常:无法创建请求的服务[org. hib. engine. jdbc. env. spi. jdbc环境]
我找不到任何样本。
application-postgres.properties is appended to have
spring.profiles.active=postgres
spring.cloud.gcp.sql.instance-connection-name= xyzprj:us-central1:postgres-instance
spring.datasource.username=xyzuser
spring.datasource.password=password
application-postgres.properties is replaced as followes
spring.datasource.username=xyzuser
spring.datasource.password=passord
spring.sql.init.mode=always
spring.cloud.gcp.sql.database-name=petclinic
spring.cloud.gcp.sql.instance-connection-name=xyzprj:us-central1:postgres-instance
后来,这两个属性文件也被更改,以便
spring.数据源.用户名= root
以及
spring.数据源.密码=根
但是在Google云内的云 shell 上尝试相同的问题样本,
gcloud身份验证应用程序-默认登录
你正在Google Compute Engine虚拟机上运行。应用程序默认凭据将自动使用与此虚拟机关联的服务凭据,因此不必使用此命令。
如果仍决定继续,则可以访问此虚拟机的其他人可能会看到你的用户凭据。是否确实要使用你的个人帐户进行身份验证?
是否要继续(Y/n)?n
错误:(gcloud. auth. application-default. login)已被用户中止。
1条答案
按热度按时间t40tm48m1#
我尝试在我这边重现此问题,但我能够成功部署应用程序
以下是我遵循的步骤
**步骤1:**使用以下命令创建
postgresql
**步骤2:**创建数据库使用
**步骤3:**连接到PostgreSQL示例以验证连接是否已建立
**步骤4:**按照
application.properties
中的操作替换以下内容并替换
以及
**第5步:**除上述更改外
在
application.properties
中更换在
src/main/resources/application-postgres.properties
中添加在
pom.xml
文件中添加以下依赖项在
build.grable
文件中添加***注意:***运行
gcloud auth application-default login
以访问默认凭据,从而与Cloud Sql API
通信有关明确的信息,请检查此document