A production-ready template for Spring Boot projects with modern best practices and built-in infrastructure.
- Spring Boot 4.0.0 (Java 25)
- UUID Primary Keys via Hibernate
@UuidGenerator - JWT Authentication & Authorization with refresh tokens
- Role-based Security with Spring Security
- Spring Boot Actuator for health, info, and metrics endpoints
- Request Correlation ID — automatic
X-Correlation-IDheader propagation and MDC logging - Structured JSON Logging — human-readable console + JSON file output (Logstash format)
- Pagination — built into
BaseServiceand controllers via Spring DataPageable - Rate Limiting — annotation-based (
@RateLimit,@RateLimitCategory) with configurable categories - Idempotency —
@Idempotentannotation with Redis-backed request deduplication - Swagger UI for API documentation (http://localhost:8080/api/v1/swagger-ui/index.html)
- PostgreSQL, Redis, Kafka & Zookeeper — all containerized via Docker Compose
- Multi-stage Dockerfile with dependency caching and JRE runtime
- JaCoCo Code Coverage reports
- Maven Enforcer — ensures Java 25+ and Maven 3.8.7+
- Lombok and MapStruct for reduced boilerplate
- Environment Isolation — run dev, test, and prod in parallel via Docker Compose
- Unit & Integration Tests for services, controllers, and infrastructure
Note: Java 25 and Maven 3.8.7+ are required.
Click "Use this template" on GitHub, then clone your new repository:
git clone https://github.com/<your-username>/<your-repo>.git
cd <your-repo>Run the initialization script to rename packages, modules, and containers to match your project:
./init-project.sh --group-id com.acme --artifact my-app --name "My App" --author "Your Name"| Option | Description | Required |
|---|---|---|
--group-id |
Maven groupId / Java package root (e.g. com.acme) |
Yes |
--artifact |
Artifact name in kebab-case (e.g. my-app) |
Yes |
--name |
Human-readable project name (default: derived from artifact) | No |
--author |
Author name for @author tags (default: tzesh) |
No |
You can also run it interactively — omit the flags and you'll be prompted:
./init-project.shThe script will:
- Rename Java packages (
com.tzesh.springtemplate-> your package) - Rename module directories (
spring-boot-template-api-><artifact>-api, etc.) - Update Docker container names, Kafka group IDs, and all references
- Replace
@authortags if--authoris provided - Self-delete after completion
./mvnw clean install# Start PostgreSQL, Redis, Kafka
docker compose up -d db redis zookeeper kafka
# Run the application
./mvnw -pl spring-boot-template-api spring-boot:runOr run everything with Docker:
docker compose up -dThe application will be available at http://localhost:8080/api/v1/swagger-ui/index.html.
SpringBootTemplate/
├── pom.xml # Parent POM (enforcer, JaCoCo, shared deps)
├── spring-boot-template-core/ # Core module (base classes, annotations, exceptions)
│ └── src/main/java/.../base/
│ ├── annotation/ # @RateLimit, @Idempotent, etc.
│ ├── dto/ # BaseDTO
│ ├── entity/ # BaseEntity
│ ├── exception/ # NotFoundException, RateLimitExceededException, etc.
│ ├── handler/ # @ControllerAdvice exception handlers
│ ├── mapper/ # BaseMapper (MapStruct)
│ ├── response/ # BaseResponse wrapper
│ └── service/ # BaseService (CRUD + pagination)
├── spring-boot-template-api/ # API module (controllers, services, config)
│ ├── Dockerfile # Multi-stage build
│ └── src/main/java/.../
│ ├── config/
│ │ ├── correlation/ # CorrelationIdFilter
│ │ ├── idempotency/ # IdempotencyAspect
│ │ ├── ratelimit/ # RateLimitAspect, RateLimitingFilter
│ │ └── security/ # SecurityChain, JWT filters
│ ├── controller/ # REST controllers
│ └── service/ # Business services
├── docker-compose.yml # PostgreSQL, Redis, Kafka, app
├── init-project.sh # Project initialization script
├── .editorconfig # Editor formatting rules
├── .gitattributes # Git line ending config
└── .dockerignore # Docker build exclusions
- Register a new user via
POST /auth/register - Login via
POST /auth/loginto obtain a JWT token - Authorize in Swagger UI using the
Authorizebutton - Access secured endpoints (e.g. user management requires
ADMINrole)
Health, info, and metrics are exposed at:
| Endpoint | Description |
|---|---|
GET /api/v1/actuator/health |
Application health status |
GET /api/v1/actuator/info |
Application info |
GET /api/v1/actuator/metrics |
Application metrics |
Health details are shown when authenticated with an authorized role. Kubernetes liveness and readiness probes are enabled.
Every request is assigned a correlation ID for distributed tracing:
- If the client sends an
X-Correlation-IDheader, it is reused - Otherwise, a UUID is generated automatically
- The correlation ID is added to the MDC for all log output and returned in the response header
@RateLimit(limit = 20, duration = 1, key = RateLimitKeyStrategy.USER)
@RateLimitCategory(RateLimitCategoryType.STANDARD)| Category | Default Limit | Duration |
|---|---|---|
strict |
10 req | 1 min |
standard |
60 req | 1 min |
relaxed |
200 req | 1 min |
authentication |
5 req | 1 min |
Annotate mutating endpoints with @Idempotent to prevent duplicate processing. Clients must send an Idempotency-Key header. Backed by Redis.
@PostMapping("/")
@Idempotent
public ResponseEntity<BaseResponse<UserDTO>> createUser(...) { ... }- Kafka and Zookeeper are included in Docker Compose
POST /kafka/sendsends messages to Kafka (supports optional scheduled delivery)- Consumer logs received messages
- Logging level configurable in
application.properties
Use .env files for environment-specific variables and Docker Compose override files for port/resource separation:
# Run test environment
docker compose -f docker-compose.yml -f docker-compose.test.override.yml --env-file .env.test -p myapp_test up -d
# Run prod environment
docker compose -f docker-compose.yml -f docker-compose.prod.override.yml --env-file .env.prod -p myapp_prod up -dJaCoCo reports are generated during mvn test and available at:
spring-boot-template-api/target/site/jacoco/index.html
spring-boot-template-core/target/site/jacoco/index.html
See CONTRIBUTING.md for setup instructions, code style, and PR process.
See LICENSE for details.

