← All packs

Spring Boot 3 + Java 21

Package-by-feature layout, ProblemDetail errors, Flyway + JPA rules that prevent N+1, Spring Security 6 lambda DSL, Testcontainers tests.

Download free sample (2 files)Buy · $12

Included files

FileCoversRulesScope
00-core.mdcCore conventions for a Java 21 / Spring Boot 3 service11Always on
10-api-controllers.mdcREST controller and DTO rules7Auto-attaches to src/main/java/**/*Controller.java src/main/java/**/dto/**/*.java
20-errors.mdc in free sampleError handling with ProblemDetail (RFC 9457)7Auto-attaches to src/main/java/**/*.java
30-persistence.mdc in free sampleJPA entities, repositories, transactions and Flyway migrations10Auto-attaches to src/main/java/**/*Repository.java src/main/java/**/*Entity.java src/main/resources/db/migration/** src/main/java/**/*Service.java
40-security.mdcSpring Security 6 configuration and secure coding rules9Auto-attaches to src/main/java/**/security/**/*.java src/main/java/**/*Config*.java src/main/resources/application*.yml src/main/resources/application*.properties
50-testing.mdcTesting strategy with JUnit 5, AssertJ, slices and Testcontainers9Auto-attaches to src/test/**/*.java
60-naming-style.mdcNaming and code style rules for Java sources8Auto-attaches to src/**/*.java
CLAUDE.mdClaude Code project instructions — sections: Commands, Architecture, Errors, Database, Security, Testing, Style22Always on (Claude Code)
README.mdInstall steps for Cursor and Claude Code, customization notes––

Preview: 20-errors.mdc (from the free sample)

# Error handling

- Set `spring.mvc.problemdetails.enabled=true`. All error responses are `ProblemDetail` (RFC 9457, `application/problem+json`).
- One `@RestControllerAdvice` named `GlobalExceptionHandler` in `common.error`, extending `ResponseEntityExceptionHandler`.
- Domain exceptions extend a single `abstract class DomainException extends RuntimeException` and carry an `HttpStatus` and stable `errorCode` (e.g. `ORDER_NOT_FOUND`), added as a `ProblemDetail` property.
- Use `NotFoundException`, `ConflictException`, `ValidationException` subclasses; throw from services, never from controllers.
- Never catch `Exception` just to log and rethrow. Catch only what you can handle.
- Unhandled exceptions → 500 with a generic detail; log the stack trace once, server-side, with a correlation id. Never return stack traces or SQL messages to clients.
- `Optional` is a return type only: `repo.findById(id).orElseThrow(() -> new NotFoundException("Order", id))`.