{"id":19331376,"url":"https://github.com/andriykalashnykov/spring-boot-rest-example","last_synced_at":"2025-04-22T23:31:56.967Z","repository":{"id":44783786,"uuid":"227662332","full_name":"AndriyKalashnykov/spring-boot-rest-example","owner":"AndriyKalashnykov","description":"Spring Boot REST microservice","archived":false,"fork":false,"pushed_at":"2024-01-22T17:19:29.000Z","size":390,"stargazers_count":5,"open_issues_count":2,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-18T23:46:00.564Z","etag":null,"topics":["kubernetes","microservice","minikube","rest-api","sdkman","spring-boot","swagger"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AndriyKalashnykov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-12T17:37:17.000Z","updated_at":"2022-07-14T05:28:43.000Z","dependencies_parsed_at":"2022-09-19T06:20:41.093Z","dependency_job_id":null,"html_url":"https://github.com/AndriyKalashnykov/spring-boot-rest-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndriyKalashnykov%2Fspring-boot-rest-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndriyKalashnykov%2Fspring-boot-rest-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndriyKalashnykov%2Fspring-boot-rest-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndriyKalashnykov%2Fspring-boot-rest-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndriyKalashnykov","download_url":"https://codeload.github.com/AndriyKalashnykov/spring-boot-rest-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250340322,"owners_count":21414526,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kubernetes","microservice","minikube","rest-api","sdkman","spring-boot","swagger"],"created_at":"2024-11-10T02:39:50.705Z","updated_at":"2025-04-22T23:31:56.692Z","avatar_url":"https://github.com/AndriyKalashnykov.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![test](https://github.com/AndriyKalashnykov/spring-boot-rest-example/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/AndriyKalashnykov/spring-boot-rest-example/actions/workflows/test.yml)\n[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FAndriyKalashnykov%2Fspring-boot-rest-example\u0026count_bg=%2379C83D\u0026title_bg=%23555555\u0026icon=\u0026icon_color=%23E7E7E7\u0026title=hits\u0026edge_flat=false)](https://hits.seeyoufarm.com)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n# Spring Boot REST microservice\n\nJava / Maven / Spring Boot microservice\n\n* Full integration with the latest **Spring** Framework 2.x: inversion of control, dependency injection, etc.\n* Packaging as a single jar with embedded container (tomcat 8)\n* Demonstrates how to set up healthcheck, metrics, info, environment, etc. endpoints automatically on a configured port. Inject your own health / metrics info with a few lines of code.\n* RESTful service using annotation: supports both XML and JSON request / response\n* Exception mapping from application exceptions to the right HTTP response with exception details in the body\n* *Spring Data* Integration with JPA/Hibernate\n* CRUD functionality with H2 in-memory data source using Spring *Repository* pattern\n* MockMVC test framework\n* Self-documented APIs: Swagger2 using annotations\n\n## Pre-requisites\n\n* [sdkman](https://sdkman.io/install)\n* [Apache Maven](https://maven.apache.org/install.html)\n* [curl](https://help.ubidots.com/en/articles/2165289-learn-how-to-install-run-curl-on-windows-macosx-linux)\n* [jq](https://github.com/stedolan/jq/wiki/Installation)\n* [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)\n* [http](https://httpie.io/cli)\n* [minikube](https://minikube.sigs.k8s.io/docs/start/)\n* [Docker](https://docs.docker.com/engine/install/)\n\n## Build and Run\n\nThis application is packaged as a jar which has Tomcat 8 embedded.\n\n* Clone this repository\n\n```bash\ngit clone git@github.com:AndriyKalashnykov/spring-boot-rest-example.git\ncd spring-boot-rest-example\n```\n* Select JDK\n\n```bash\nsdk install java 18.0.1-tem\nsdk use java 18.0.1-tem\n```\n* Build the project and run the tests by running\n\n```bash\nmvn clean package\n```\n* Run the service\n\n```\n  mvn clean spring-boot:run -Dspring-boot.run.profiles=default\n```\n\n### Swagger UI documentation links, application health, configurations \n\n```\nhttp://localhost:8080/swagger-ui/#/hotels\n\nhttp://localhost:8080/actuator/env\nhttp://localhost:8080/actuator/health\nhttp://localhost:8080/actuator/info\nhttp://localhost:8080/actuator/metrics\nhttp://localhost:8080/actuator/configprops\n\n```\n\n### Microservice API\n\n```\ncurl -X POST 'http://localhost:8080/v1/hotels' --header 'Content-Type: application/json' --header 'Accept: application/json' --data @hotel.json --stderr -\n```\nor\n```\nhttp POST 'http://localhost:8080/v1/hotels' \u003c hotel.json\n```\nor\n```\ncurl -X POST 'http://localhost:8080/v1/hotels' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{\"name\":\"Beds R Us\",\"description\":\"Very basic, small rooms but clean\",\"city\":\"Santa Ana\",\"rating\":2}' --stderr -\n```\n\n### Retrieve a paginated list of hotels\n\n```\ncurl -X GET --silent 'http://localhost:8080/v1/hotels?page=0\u0026size=10' --stderr -  2\u003e\u00261 | jq .\n```\nor\n```\nhttp  'http://localhost:8080/v1/hotels?page=0\u0026size=10'\n```\n### Swagger 2 API docs\n\n```\nxdg-open http://localhost:8080/swagger-ui/#/hotels\n```\n\n\n### Building docker image\n\n\n#### Optional, local test only: Using local maven cache\n\n  In order to build image quickly by compiling maven project using host OS  maven repo\n\n  Build project, artifact will be placed in $PWD/target\n\n  ```\n  cd spring-boot-rest-example\n  docker run -v ~/.m2:/root/.m2 -v \"$PWD\":/usr/src -w /usr/src maven:3-jdk-8 mvn clean package\n  ```\n\n  #### Build non multi-stage image using existing artifact in $PWD/target\n\n  ```\n  cd spring-boot-rest-example\n  docker rm -f spring-boot-rest-example\n  docker build  -f Dockerfile.maven-host-cache -t spring-boot-rest-example .\n  ```\n\n  #### Build  multi-stage image  \n\n  ```\n  docker rm -f spring-boot-rest-example\n  docker build  -f Dockerfile.maven-multi-stage-layer-cached -t spring-boot-rest-example .\n  ```\n\n  #### Test application\n\n  ```\n  docker run --name spring-boot-rest-example -p 8080:8080 spring-boot-rest-example:latest\n\n  curl -X POST 'http://localhost:8080/v1/hotels' --header 'Content-Type: application/json' --header 'Accept: application/json' --data @hotel.json --stderr -\n\n  curl -X GET --silent 'http://localhost:8080/v1/hotels?page=0\u0026size=10' --stderr -  2\u003e\u00261 | jq .\n\n  ```\n\n### Attaching to the application from IDE\n\nRun the service with these command line options:\n\n```\nmvn spring-boot:run -Drun.jvmArguments=\"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005\"\n```\nor\n\n```\njava -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -Dspring.profiles.active=test -Ddebug -jar target/spring-boot-rest-example-0.0.1.jar\n```\n\nIntelliJ : Run -\u003e Edit configuration -\u003e Remote.\n\n![IntelliJ IDEA](./img/idea-remote.png)\n\n### Deploy application to k8s\n\n```\nminikube delete --all\nminikube start -p minikube --memory=16384 --cpus=6 --disk-size=30g --vm-driver=virtualbox\neval $(minikube docker-env)\neval \"$(docker-machine env -u)\"\n# minikube start --vm-driver=virtualbox --extra-config=apiserver.anonymous-auth=false --insecure-registry=localhost:5000\n\n# deploy to k8s\n\nminikube ssh 'docker logs $(docker ps -a -f name=k8s_kube-api --format={{.ID}})'\n```\n\n### Test deployed application\n\n```\ncurl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --data @hotel.json $(minikube service spring-boot-rest-example --url | sed -n 1p)/v1/hotels\nhttp $(minikube service spring-boot-rest-example --url | sed -n 1p)/v1/hotels?page=0\u0026size=10\n\nhttp $(minikube service spring-boot-rest-example --url | sed -n 2p)/swagger-ui.html\nhttp $(minikube service spring-boot-rest-example --url | sed -n 2p)/info\nhttp $(minikube service spring-boot-rest-example --url | sed -n 2p)/health\n```\n\n### Monitor k8s resources\n```\nkubectl get nodes --no-headers | awk '{print $1}' | xargs -I {} sh -c 'echo {}; kubectl describe node {} | grep Allocated -A 5 | grep -ve Event -ve Allocated -ve percent -ve -- ; echo'\nkubectl top pod --all-namespaces\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandriykalashnykov%2Fspring-boot-rest-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandriykalashnykov%2Fspring-boot-rest-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandriykalashnykov%2Fspring-boot-rest-example/lists"}