This repository contains a tutorial project demonstrating how to build and run a simple RESTful Spring Boot application connected to a PostgreSQL database using Docker Compose.
It follows a learning-oriented approach inspired by educational resources such as Amigoscode’s Spring Boot with PostgreSQL tutorials. The project is intended for educational and practice purposes, showcasing clean setup, integration, and deployment patterns.
- Build REST APIs using Spring Boot 3
- Connect and persist data in PostgreSQL
- Run PostgreSQL via Docker Compose
- Manage dependencies with Maven
- Demonstrate clean architecture: Controller → Service → Repository → Database
| Component | Technology |
|---|---|
| Language | Java 21 |
| Framework | Spring Boot 3.x |
| Database | PostgreSQL (Dockerized) |
| Build Tool | Maven |
| Containerization | Docker & Docker Compose |
| IDE | IntelliJ IDEA |
Before running this project, make sure you have:
git clone https://github.com/abhip-10/spring-boot-postgres.git
cd spring-boot-postgresdocker compose up -dThis starts a PostgreSQL container named postgres-spring-boot on port 5332 (mapped to internal port 5432).
docker psYou should see something like:
CONTAINER ID IMAGE PORTS
abc1234 postgres:latest 0.0.0.0:5332->5432/tcp
src/main/resources/application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5332/postgres
spring.datasource.username=abhi
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=trueOption 1: Using Maven
mvn spring-boot:runOption 2: Build a JAR and Run
mvn clean package
java -jar target/app.jarOnce started, open your browser or API client at: http://localhost:8080
Endpoint: POST http://localhost:8080/api/v1/software-engineers
Request Body:
{
"name": "Abhinav",
"techStack": "Java, Spring Boot, Spring"
}Response: HTTP 200 OK (no body, simple insert)
docker-compose.yml:
services:
db:
container_name: postgres-spring-boot
image: postgres:latest
environment:
POSTGRES_USER: amigoscode
POSTGRES_PASSWORD: password
PGDATA: /data/postgres
volumes:
- db:/data/postgres
ports:
- "5332:5432"
networks:
- db
restart: unless-stopped
volumes:
db:
networks:
db:
driver: bridgeThrough this tutorial project, you’ll learn to:
- Set up a full Spring Boot + PostgreSQL environment
- Connect Spring Boot to a database via JDBC and JPA
- Manage PostgreSQL containers using Docker Compose
- Write and test REST endpoints
- Build, package, and containerize a Java backend service
spring-boot-postgres/
│
├── src/
│ ├── main/
│ │ ├── java/com/abhi/...
│ │ │ ├── controller/ # REST controllers
│ │ │ ├── service/ # Business logic
│ │ │ ├── model/ # Entities
│ │ │ └── repository/ # Data access layer
│ │ └── resources/
│ │ ├── application.properties
│ │ └── data.sql (optional for init)
│
├── docker-compose.yml
├── Dockerfile
├── pom.xml
└── README.md
This project is licensed under the MIT License. You are free to use, modify, and distribute it for educational purposes.