← ClaudeAtlas

java-spring-conventionslisted

Senior Java + Spring Boot conventions, idioms, and pitfalls — dependency injection, transaction boundaries, layering, validation, exception handling, JPA/N+1, reactive (WebFlux), and testing. Use when writing, reviewing, or porting Java/Spring code. Loads on top of the project's own style — the project's conventions always win.
vinaygiri/fleetmind · ★ 2 · Code & Development · score 70
Install: claude install-skill vinaygiri/fleetmind
# Java / Spring Boot conventions Senior defaults. **The project's existing style and build config always win** — read them first and match; this is the baseline when the project is silent. ## Core Java - Favor immutability: `final` fields, `record`s for DTOs/value objects. Return `Optional<T>` for "maybe absent"; never return `null` collections (return empty). Avoid `Optional` as a field/param. - Prefer streams for transformation but keep them readable; watch boxing and N+1 lambdas on hot paths. Use `equals`/`hashCode` correctly (records give them free). - Specific exceptions over generic; never swallow; never `catch (Exception)` and continue silently. ## Spring Boot - **Constructor injection** (final fields), not `@Autowired` on fields — makes deps explicit and testable. - Layering: `@RestController` (thin) → `@Service` (business logic) → repository. Keep DTOs distinct from JPA entities; map explicitly. - **`@Transactional` pitfalls:** only works through the Spring proxy — self-invocation within the same bean bypasses it; rollback is on unchecked exceptions by default (set `rollbackFor` for checked). Keep transaction scope tight; no remote calls inside a DB transaction. - Validation with Bean Validation (`@Valid`, `@NotNull`, etc.) at the controller boundary. - **Exception handling:** `@RestControllerAdvice` + `@ExceptionHandler` mapping to proper status codes; return a clean error body — never leak stack traces or `ex.getMessage()`/PHI to clients. - Config via `@Configur