A practical starter kit for building Spring Boot microservices with service discovery, gateway routing, JWT authentication, and inter-service communication.
This project is designed for two outcomes:
- Faster onboarding for developers starting with Spring Boot microservices.
- A production-leaning base template you can fork, extend, containerize, and deploy.
- Java 21
- Spring Boot 4.0.1
- Spring Cloud 2025.1.0
- Eureka (service discovery)
- Spring Cloud Gateway (routing + auth filter)
- OpenFeign (service-to-service calls)
- MySQL / MariaDB
- Docker + Docker Compose
naming-server: Eureka naming serverapi-gateway: request gateway and JWT validationuser-service: authentication, users, rolestemplate-service: template microservice with Feign integration
- Client signs in via
api-gateway(/auth/sign-in->user-service). user-serviceissues JWT token withsession-userclaim.- Client calls secured routes through
api-gateway. - Gateway validates token and forwards user context to downstream services.
- Services discover each other through
naming-server.
CIworkflow runs on pull requests tomain, pushes tomain, and manual dispatch.- CI validates each service with Maven
verifyand runs a Docker Compose smoke test for the full stack. Docker Publishworkflow runs only on version tags (v*) or manual dispatch.- Merging to
maindoes not push images to Docker Hub by default.
Required GitHub repository secrets for image publishing:
DOCKERHUB_USERNAMEDOCKERHUB_TOKEN
cp .env.example .envEdit .env if needed (ports, DB password, JWT secret, Docker Hub username).
Default host ports use a predictable, lower-conflict scheme:
- MySQL:
13306 - Naming server:
18761 - API Gateway:
18765 - User service:
18000 - Template service:
18100
Internal container ports remain standard (3306, 8761, 8765, 8000, 8100) for service-to-service communication.
If any of these are still taken on your machine, override values in .env (or inline):
API_GATEWAY_PORT=19765 docker compose up -ddocker compose up -dThis pulls and runs the published Docker Hub images.
If you changed code locally and want to rebuild images from source, package each service first, then run:
(cd naming-server && mvn -q -DskipTests package)
(cd user-service && mvn -q -DskipTests package)
(cd template-service && mvn -q -DskipTests package)
(cd api-gateway && mvn -q -DskipTests package)
docker compose up --build -ddocker compose ps- Naming server:
http://localhost:18761 - API Gateway:
http://localhost:18765 - User service:
http://localhost:18000 - Template service:
http://localhost:18100
docker compose downTo remove DB volume too:
docker compose down -vRun each service in separate terminals:
cd naming-server && mvn spring-boot:run
cd user-service && mvn spring-boot:run
cd template-service && mvn spring-boot:run
cd api-gateway && mvn spring-boot:runSee .env.example for the full list.
Key values:
DB_PORT=13306USER_DB_NAME=users_dbTEMPLATE_DB_NAME=canvaJWT_SECRET=...DOCKERHUB_USERNAME=slubambo
- On release tag push (for example
v1.0.0), GitHub Actions builds and publishes multi-arch images. - You can also trigger publish manually from the
Docker Publishworkflow and provide a custom tag.
This repo includes scripts/build-and-push-images.sh, which follows your buildx approach and pushes all 4 service images.
- Login to Docker Hub
docker login- Build and push
DOCKERHUB_USERNAME=slubambo IMAGE_TAG=latest ./scripts/build-and-push-images.shIt pushes:
slubambo/springboot-ms-naming-server:latestslubambo/springboot-ms-user-service:latestslubambo/springboot-ms-template-service:latestslubambo/springboot-ms-api-gateway:latest
docker buildx create --name multiarch --use
docker buildx inspect --bootstrap
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t slubambo/springboot-ms-api-gateway:latest \
-f api-gateway/Dockerfile \
api-gateway \
--pushRepeat for the other service folders and image tags.
user-serviceauto-createsROLE_USERandROLE_ADMINat startup when missing.- Use strong secrets in
.envfor real deployments. spring-cloud-configis optional and disabled indocker-compose.yml.
- Read
CONTRIBUTING.mdbefore opening issues or pull requests. - Use the built-in GitHub issue templates for bugs and feature requests.
- Maintainers should apply labels using
.github/LABELS.md.
.
├── api-gateway/
├── naming-server/
├── template-service/
├── user-service/
├── docker-compose.yml
├── .env.example
└── scripts/build-and-push-images.sh
Licensed under the MIT License.