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.
- 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 | 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 |
- Java 17 or higher
- Maven 3.6+
- (Optional) Docker for containerization
- (Optional) Kubernetes/OpenShift for deployment
- Clone the repository
git clone https://github.com/piomin/sample-spring-kotlin-microservice.git
cd sample-spring-kotlin-microservice
- Run with Maven
mvn spring-boot:run
- Access the application
- Application: http://localhost:8080
- Swagger UI: http://localhost:8080/swagger-ui.html
- Health Check: http://localhost:8080/actuator/health
- Metrics: http://localhost:8080/actuator/prometheus
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 |
Method | Endpoint | Description |
---|---|---|
GET | /envs | Get environment password variable |
# 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
# Build with Jib (preferred)
mvn clean compile jib:dockerBuild -Pjib
# Build with Dockerfile
docker build -t sample-spring-kotlin-microservice .
kubectl apply -f k8s/
kubectl get pods -l app=sample-spring-kotlin-microservice
kubectl port-forward svc/sample-spring-kotlin-microservice 8080:8080
oc process -f openshift/app.yaml \
-p namespace=my-project \
-p version=latest | oc apply -f -
# Run all tests
mvn test
# Run a specific test class
mvn test -Dtest=PersonControllerTests
# Generate coverage report
mvn clean test jacoco:report
curl http://localhost:8080/actuator/health
curl http://localhost:8080/actuator/metrics
curl http://localhost:8080/actuator/prometheus
spring:
application.name: sample-spring-kotlin-microservice
management:
endpoints.web.exposure.include: '*'
endpoint.health:
show-details: always
probes.enabled: true
app:
delay: 20
- Import as Maven project
- Install Kotlin plugin
- Set Project SDK to Java 17
- Enable annotation processing
- Install Extension Pack for Java
- Kotlin Language Support
- Spring Boot Extension Pack
- Azure DevOps pipeline for build, test, and container image creation
- SonarCloud integration for quality gate
- Automatic triggers on master and PR validation
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
- Fork the repo
- Create a feature branch (
git checkout -b feature/awesome
) - Commit changes (
git commit -m 'feat: awesome feature'
) - Push and open a PR
This project is provided as a sample/demo for educational purposes.
For questions, open an issue or refer to:
- Spring Boot Docs: https://spring.io/projects/spring-boot
- Kotlin Docs: https://kotlinlang.org/docs/