Skip to content

sample spring boot application written in kotlin using spring boot actuator for managing app and swagger2 for API documentation

Notifications You must be signed in to change notification settings

piomin/sample-spring-kotlin-microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Kotlin Microservice with Spring Boot Twitter

CircleCI

SonarCloud Bugs Coverage Lines of Code

Detailed description can be found here: Kotlin Microservice with Spring Boot

A demonstration microservice built with Spring Boot and Kotlin showcasing modern microservice patterns, cloud-native development, and DevOps practices.

πŸš€ Features

  • RESTful API for Person entity management (CRUD operations)
  • In-memory data store with 1000 auto-generated fake records using DataFaker
  • Spring Boot Actuator integration with health checks and metrics
  • Prometheus metrics exposure for monitoring
  • OpenAPI/Swagger documentation
  • Multiple web server support (Tomcat, Jetty, Undertow)
  • Cloud-native deployment configurations (Kubernetes, OpenShift)
  • Containerization with Jib Maven plugin
  • CI/CD pipeline with Azure DevOps
  • Development tools integration (Skaffold, DevFile)

πŸ›  Technology Stack

Technology Version Purpose
Spring Boot 3.5.0 Application framework
Kotlin 2.1.21 Programming language
Java 17 Runtime platform
Maven 3.6+ Build tool
SpringDoc OpenAPI 2.8.8 API documentation
Micrometer 1.11.4 Metrics collection
DataFaker 2.4.3 Test data generation
Instancio 5.4.1 Test object creation

πŸƒβ€β™‚οΈ Quick Start

Prerequisites

  • Java 17 or higher
  • Maven 3.6+
  • (Optional) Docker for containerization
  • (Optional) Kubernetes/OpenShift for deployment

Running the Application

  1. Clone the repository
git clone https://github.com/piomin/sample-spring-kotlin-microservice.git
cd sample-spring-kotlin-microservice
  1. Run with Maven
mvn spring-boot:run
  1. Access the application

πŸ“‹ API Documentation

Person Management Endpoints

Method Endpoint Description Response
GET /persons Retrieve all persons List
GET /persons/{id} Get person by ID Person
GET /persons/ages/{age} Find persons by age List
GET /persons/delayed Get all persons with random delay List
POST /persons Create new person Person
PUT /persons Update existing person Person
DELETE /persons/{id} Delete person by ID Boolean

Environment Endpoint

Method Endpoint Description
GET /envs Get environment password variable

πŸ”§ Build & Package

Maven Commands

# Compile and run tests
mvn clean compile test

# Package application
mvn clean package

# Skip tests during build
mvn clean package -DskipTests

# Run with a specific profile (jetty, undertow)
mvn spring-boot:run -Pjetty

Docker Build

# Build with Jib (preferred)
mvn clean compile jib:dockerBuild -Pjib

# Build with Dockerfile
docker build -t sample-spring-kotlin-microservice .

☸️ Deployment

Kubernetes

kubectl apply -f k8s/
kubectl get pods -l app=sample-spring-kotlin-microservice
kubectl port-forward svc/sample-spring-kotlin-microservice 8080:8080

OpenShift

oc process -f openshift/app.yaml \
  -p namespace=my-project \
  -p version=latest | oc apply -f -

πŸ§ͺ Testing

# Run all tests
mvn test

# Run a specific test class
mvn test -Dtest=PersonControllerTests

# Generate coverage report
mvn clean test jacoco:report

πŸ“Š Monitoring & Observability

curl http://localhost:8080/actuator/health
curl http://localhost:8080/actuator/metrics
curl http://localhost:8080/actuator/prometheus

βš™οΈ Configuration

application.yml highlights

spring:
  application.name: sample-spring-kotlin-microservice
management:
  endpoints.web.exposure.include: '*'
  endpoint.health:
    show-details: always
    probes.enabled: true
app:
  delay: 20

πŸ”¨ Development Setup

IntelliJ IDEA

  1. Import as Maven project
  2. Install Kotlin plugin
  3. Set Project SDK to Java 17
  4. Enable annotation processing

VS Code

  • Install Extension Pack for Java
  • Kotlin Language Support
  • Spring Boot Extension Pack

🚦 CI/CD Pipeline

  • Azure DevOps pipeline for build, test, and container image creation
  • SonarCloud integration for quality gate
  • Automatic triggers on master and PR validation

πŸ“ Project Structure

sample-spring-kotlin-microservice/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/kotlin/pl/piomin/services/
β”‚   β”œβ”€β”€ main/resources/application.yml
β”‚   └── test/kotlin/pl/piomin/services/
β”œβ”€β”€ k8s/
β”œβ”€β”€ openshift/
β”œβ”€β”€ azure-pipelines.yml
β”œβ”€β”€ skaffold.yaml
β”œβ”€β”€ devfile.yaml
β”œβ”€β”€ Dockerfile
└── pom.xml

🀝 Contributing

  1. Fork the repo
  2. Create a feature branch (git checkout -b feature/awesome)
  3. Commit changes (git commit -m 'feat: awesome feature')
  4. Push and open a PR

πŸ“ License

This project is provided as a sample/demo for educational purposes.

πŸ“ž Support

For questions, open an issue or refer to:

About

sample spring boot application written in kotlin using spring boot actuator for managing app and swagger2 for API documentation

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published