简体   繁体   中英

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. I am able to connect using Spring Cloud GCP starter project.

<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.

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. According to https://cloud.google.com/run/docs/configuring/connect-cloudsql , --add-cloudsql-instances automatically creates a Cloud proxy. So why doesn't it work?

Thanks.

This doesn't work because Java doesn't support Unix domain sockets. The Spring Cloud GCP circumvents this by using the 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM