A simple Spring Boot application with PostgreSQL database integration using Docker Compose.
- Java 21 (Latest LTS)
- Spring Boot 3.4.1 (Latest version)
- PostgreSQL 16 (Latest version)
- Docker & Docker Compose
- Maven
- Docker and Docker Compose installed
- Java 21 (if running locally without Docker)
- Maven (if building locally)
-
Clone/navigate to the project directory
-
Start the application and database:
docker-compose up --build
-
The application will be available at
http://localhost:8080 -
PostgreSQL will be available at
localhost:5432
-
Start only the PostgreSQL database:
docker-compose up postgres
-
Run the Spring Boot application:
./mvnw spring-boot:run
The application includes a simple User management API:
GET /api/users- Get all usersGET /api/users/{id}- Get user by IDPOST /api/users- Create new userPUT /api/users/{id}- Update userDELETE /api/users/{id}- Delete user
Create a user:
curl -X POST http://localhost:8080/api/users \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "email": "john@example.com"}'Get all users:
curl http://localhost:8080/api/users- Database:
demodb - Username:
demo - Password:
demo123 - Port:
5432
├── src/main/java/com/example/demo/
│ ├── DemoApplication.java # Main application class
│ ├── controller/
│ │ └── UserController.java # REST controller
│ ├── entity/
│ │ └── User.java # JPA entity
│ └── repository/
│ └── UserRepository.java # JPA repository
├── src/main/resources/
│ └── application.yml # Application configuration
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Application container
└── pom.xml # Maven dependencies
docker-compose downTo remove volumes as well:
docker-compose down -v