Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Supabase as a database for a Spring Boot application?

I’m working on a Spring Boot application and I’d like to use Supabase database as my database.

I’ve successfully set up Supabase and created a project, but I’m having trouble configuring it in my Spring Boot application, and also trouble with an endpoint of mine.

My current setup:

  • Spring Boot version: 3.2.5

What I’ve tried:

  1. Added the necessary PostgreSQL dependencies to my pom.xml:

    <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId></dependency>

  2. Configured my application.properties with the details provided by Supabase:

spring.datasource.url=jdbc:postgresql://<supabase-host>:5432/<database-name>
spring.datasource.username=<supabase-user> 
spring.datasource.password=<supabase-password>
spring.datasource.driver-class-name=org.postgresql.Driver

I’m not sure if this configuration is sufficient or if there are additional settings required to fully integrate Supabase with Spring Boot.

like image 246
Gabriele Avatar asked Jan 21 '26 22:01

Gabriele


2 Answers

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url={YOUR JDBC URL}&password={YOUR SUPABASE DB PASSWORD}
spring.datasource.username={Your DB User Name From Supabase}
spring.datasource.password={Your DB Password From Supabase}
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none

You need to get the JDBC connection String from connect --> Type --> JDBC and scroll to Session Pooler to get the JDBC URL and credentials.

For step by step process please see my blog below:https://medium.com/@khan.abdulwasey99/step-by-step-process-on-how-to-connect-a-spring-boot-application-to-supabase-f1791e1d2402

Re-posting I was not aware of Stackoverflow guidelines for external blogs.

like image 159
Abdul Wasey Khan Avatar answered Jan 24 '26 14:01

Abdul Wasey Khan


You can do something like that :

# Supabase configuration
supabase.url=${SUPABASE_URL}
supabase.anon=${SUPABASE_ANON_KEY}
supabase.jwt_secret=${SUPABASE_JWT_SIGNER}

# Spring application configuration
spring.application.name=Demo
spring.main.banner-mode=off

# Spring datasource configuration
spring.datasource.url=${SUPABASE_DATABASE_URL}
spring.datasource.username=${SUPABASE_DATABASE_USER}
spring.datasource.password=${SUPABASE_DATABASE_PASSWORD}
spring.datasource.driverClassName=org.postgresql.Driver

like image 24
amir BEN AHMED Avatar answered Jan 24 '26 14:01

amir BEN AHMED