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
| File | Covers | Rules | Scope |
|---|---|---|---|
00-core.mdc | Core conventions for a Java 21 / Spring Boot 3 service | 11 | Always on |
10-api-controllers.mdc | REST controller and DTO rules | 7 | Auto-attaches to src/main/java/**/*Controller.java src/main/java/**/dto/**/*.java |
20-errors.mdc in free sample | Error handling with ProblemDetail (RFC 9457) | 7 | Auto-attaches to src/main/java/**/*.java |
30-persistence.mdc in free sample | JPA entities, repositories, transactions and Flyway migrations | 10 | Auto-attaches to src/main/java/**/*Repository.java src/main/java/**/*Entity.java src/main/resources/db/migration/** src/main/java/**/*Service.java |
40-security.mdc | Spring Security 6 configuration and secure coding rules | 9 | Auto-attaches to src/main/java/**/security/**/*.java src/main/java/**/*Config*.java src/main/resources/application*.yml src/main/resources/application*.properties |
50-testing.mdc | Testing strategy with JUnit 5, AssertJ, slices and Testcontainers | 9 | Auto-attaches to src/test/**/*.java |
60-naming-style.mdc | Naming and code style rules for Java sources | 8 | Auto-attaches to src/**/*.java |
CLAUDE.md | Claude Code project instructions — sections: Commands, Architecture, Errors, Database, Security, Testing, Style | 22 | Always on (Claude Code) |
README.md | Install 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))`.