Skip to content

proceduretech/java-interview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot PostgreSQL Demo

A simple Spring Boot application with PostgreSQL database integration using Docker Compose.

Technologies Used

  • Java 21 (Latest LTS)
  • Spring Boot 3.4.1 (Latest version)
  • PostgreSQL 16 (Latest version)
  • Docker & Docker Compose
  • Maven

Prerequisites

  • Docker and Docker Compose installed
  • Java 21 (if running locally without Docker)
  • Maven (if building locally)

Quick Start

Using Docker Compose (Recommended)

  1. Clone/navigate to the project directory

  2. Start the application and database:

    docker-compose up --build
  3. The application will be available at http://localhost:8080

  4. PostgreSQL will be available at localhost:5432

Local Development

  1. Start only the PostgreSQL database:

    docker-compose up postgres
  2. Run the Spring Boot application:

    ./mvnw spring-boot:run

API Endpoints

The application includes a simple User management API:

  • GET /api/users - Get all users
  • GET /api/users/{id} - Get user by ID
  • POST /api/users - Create new user
  • PUT /api/users/{id} - Update user
  • DELETE /api/users/{id} - Delete user

Example Usage

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 Configuration

  • Database: demodb
  • Username: demo
  • Password: demo123
  • Port: 5432

Project Structure

├── 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

Stopping the Application

docker-compose down

To remove volumes as well:

docker-compose down -v

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published