[英]Connect from Spring boot app running on Google Cloud Run to a Cloudsql without GCP starter
I have a Spring boot app running on Google Cloud Run, and I want to connect to a postgres instance running on Google Cloudsql.我有一个在 Google Cloud Run 上运行的 Spring 启动应用程序,我想连接到在 Google Cloudsql 上运行的 postgres 实例。 I am able to connect using Spring Cloud GCP starter project.
我可以使用 Spring Cloud GCP 入门项目进行连接。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
</dependency>
But I don't want to add this dependency.但我不想添加这个依赖。
I was able to connect from my local app by using using the postgressql plugin and specifying spring.datasource.url=***
after creating a Cloud proxy.在创建云代理后,我可以使用 postgressql 插件并指定
spring.datasource.url=***
从本地应用程序连接。
But when I tried doing the same from cloud run after using gcloud beta run deploy --add-cloudsql-instances <INSTANCE-ID>
it doesn't work.但是,当我在使用
gcloud beta run deploy --add-cloudsql-instances <INSTANCE-ID>
后尝试从云运行中执行相同操作时,它不起作用。 According to https://cloud.google.com/run/docs/configuring/connect-cloudsql , --add-cloudsql-instances
automatically creates a Cloud proxy.根据https://cloud.google.com/run/docs/configuring/connect-cloudsql ,
--add-cloudsql-instances
自动创建云代理。 So why doesn't it work?那么为什么它不起作用呢?
Thanks.谢谢。
This doesn't work because Java doesn't support Unix domain sockets.这不起作用,因为 Java 不支持 Unix 域 sockets。 The Spring Cloud GCP circumvents this by using the Cloud SQL JDBC Socket Factory .
Spring Cloud GCP 通过使用Cloud SQL JDBC Socket Factory来规避此问题。
You can use the Socket Factory directly by adding it your your pom (and updating your URL as specified in the README).您可以通过添加您的 pom 直接使用 Socket Factory(并按照自述文件中的说明更新您的 URL)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.