I've been trying to connect my spring boot service to Google cloud Postgres instance but facing an issue. I'm migrating a service from golang, that's using a connector to communicate with the database, to spring boot service. I am following this tutorial provided by GCP github account
pom
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-dependencies</artifactId>
<version>4.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
...
<!-- Database Driver -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
</dependency>
application.properties
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.sql.init.mode=always
# GCP settings
gcp.project=project_id
gcp.project.region=project_region
gcp.postgres.instance=postgres_instance_id
gcp.postgres.database=database_name
# PostgreSQL connection
spring.cloud.gcp.project-id=${gcp.project}
spring.cloud.gcp.sql.instance-connection-name=${gcp.project}:${gcp.project.region}:${gcp.postgres.instance}
spring.cloud.gcp.sql.database-name=${gcp.postgres.database}
spring.datasource.url=jdbc:postgresql:///${gcp.postgres.database}?cloudSqlInstance=${gcp.project}:${gcp.project.region}:${gcp.postgres.instance}&socketFactory=com.google.cloud.sql.postgres.SocketFactory
spring.datasource.username=db_user
spring.datasource.password=db_pass
When I run my spring boot app from Intellij I always get:
2025-11-13T15:03:09.275+01:00 WARN 36220 --- [management] [ main] c.g.a.oauth2.DefaultCredentialsProvider : Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/.
2025-11-13T15:04:09.460+01:00 WARN 36220 --- [management] [ main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Pool is empty, failed to create/setup connection (3ddfd9fb-cb9a-4533-9dfe-3fd0ded3b497)
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:385) ~[postgresql-42.7.8.jar:42.7.8]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:57) ~[postgresql-42.7.8.jar:42.7.8]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:279) ~[postgresql-42.7.8.jar:42.7.8]
at org.postgresql.Driver.makeConnection(Driver.java:448) ~[postgresql-42.7.8.jar:42.7.8]
at org.postgresql.Driver.connect(Driver.java:298) ~[postgresql-42.7.8.jar:42.7.8]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:144) ~[HikariCP-6.3.3.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:370) ~[HikariCP-6.3.3.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:207) ~[HikariCP-6.3.3.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:488) ~[HikariCP-6.3.3.jar:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:576) ~[HikariCP-6.3.3.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:97) ~[HikariCP-6.3.3.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:111) ~[HikariCP-6.3.3.jar:na]
...
Caused by: java.net.SocketException: Connection reset
What am I doing wrong?