Skip to content

Device microservice (Spring Boot, Docker, MySQL)

Notifications You must be signed in to change notification settings

Saurabh97/device

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Device Service – Spring Boot Microservice

A Spring Boot–based Device Management microservice that provides REST APIs to create, update, fetch, and delete devices.
The application uses MySQL as the database, is containerized using Docker Compose, and the Docker image is built using Google Jib.


Features

  • CRUD REST APIs for device management
  • Input validation using Jakarta Bean Validation
  • Global exception handling with custom error responses
  • MySQL database integration using Spring Data JPA
  • Dockerized using Docker Compose
  • Image built using Google Jib (no Dockerfile required)
  • Swagger UI for API documentation
  • Unit tests for Controller and Service layers

Tech Stack

  • Java 24
  • Spring Boot 3.5.9
  • Spring Data JPA
  • Hibernate
  • MySQL 8.0
  • Docker & Docker Compose
  • Google Jib
  • JUnit 5 & Mockito
  • Swagger (springdoc-openapi)

Project Structure

device/ ├── src/main/java/com/example/device │ ├── controller │ ├── service │ ├── service/impl │ ├── repository │ ├── entity │ ├── dto │ ├── exception │ └── constant ├── src/test/java/com/example/device │ ├── controller │ └── service ├── docker-compose.yml ├── pom.xml └── README.md


REST API Endpoints

Create Device

POST /devices/create

Fetch Single Device

GET /devices/fetchsingledevice?name={name}&brand={brand}

Fetch All Devices

GET /devices/alldevices

Fetch Devices by Brand

GET /devices/bybrand?brand={brand}

Fetch Devices by State

GET /devices/devicestate?state={AVAILABLE|IN_USE}

Update Device

PUT /devices/updatedevice?name={name}&brand={brand}

Delete Device

DELETE /devices/delete?name={name}&brand={brand}


Sample Device Request Payload

{ "name": "Samsung Mobile", "brand": "Samsung Brand", "deviceState": "AVAILABLE" }


Docker & Docker Compose

The application is fully containerized using Docker Compose.

Services

  • MySQL database container
  • Device Service Spring Boot container

Run the Application

docker compose up -d


Running Tests

mvn test

Includes:

  • Controller tests using @WebMvcTest
  • Service layer tests using Mockito

Swagger UI

Once the application is running, access Swagger UI at:

http://localhost:8080/swagger-ui.html


Docker Image

The application image is built using Google Jib:

saurabh9705/device:v1

No Dockerfile is required.


Configuration

The application uses environment variables for configuration:

SPRING_DATASOURCE_URL
SPRING_DATASOURCE_USERNAME
SPRING_DATASOURCE_PASSWORD
SPRING_PROFILES_ACTIVE


Design Highlights

  • Clear separation of Controller, Service, and Repository layers
  • DTO-based API design
  • Centralized exception handling
  • Validation at API boundary
  • Container-first microservice design
  • Health-checked MySQL startup using Docker Compose

Future Enhancements

  • Pagination and sorting
  • Spring Security integration
  • Flyway database migrations
  • CI/CD using GitHub Actions
  • Kubernetes deployment

Author

Saurabh Singh
Java Backend Developer | Spring Boot | Microservices | Docker

About

Device microservice (Spring Boot, Docker, MySQL)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages