spring-framework-patterns

Provides Spring Boot best practices, code templates, and review checklists for Java applications.

Updated Dec 26, 2025
One-click install
npx skills add https://github.com/jwvdvuurst/CalculatorCollection --skill spring-framework-patterns-jwvdvuurst
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spring-framework-patterns
Source: https://github.com/jwvdvuurst/CalculatorCollection/tree/main/skills/spring-framework-patterns
Command: npx skills add https://github.com/jwvdvuurst/CalculatorCollection --skill spring-framework-patterns-jwvdvuurst

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Spring Boot codebases often accumulate anti-patterns like field injection, fat controllers, missing transaction boundaries, and inconsistent error handling. This Skill gives reviewers and developers a single authoritative reference of correct Spring Framework patterns with concrete good/bad code examples, ready-to-use templates, and a structured review checklist. ## Core Features & Use Cases - Pattern Reference: Covers dependency injection, bean scopes and lifecycle, REST controller design, Spring Data JPA repositories, service layer boundaries, DTO mapping, transaction management, and global exception handling with @RestControllerAdvice. - Code Templates: Provides parameterized Java templates for RestController, Service, Repository, and GlobalExceptionHandler classes that follow Spring Boot 3.x conventions. - Code Review Checklist: Ships a comprehensive checklist covering architecture, security, testing, performance, and common anti-patterns for systematic Spring code reviews. - Use Case: When reviewing a Spring Boot pull request, load this Skill to verify constructor injection is used, controllers delegate to services, DTOs replace entities in API responses, and @Transactional is applied at the service layer. ## Quick Start Review my Spring Boot application code using the spring-framework-patterns checklist and flag any dependency injection or layering violations.

Frequently Asked Questions about spring-framework-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement dependency injection correctly in Spring Boot?

Use constructor injection for all required dependencies, declaring them as final fields. Avoid field injection with @Autowired, which hides dependencies and complicates testing. Lombok's @RequiredArgsConstructor generates the constructor automatically.

How should a Spring Boot REST controller be structured?

Keep controllers thin by delegating business logic to services, use RESTful URLs with proper HTTP methods, return ResponseEntity with correct status codes, validate input with @Valid, and expose DTOs instead of JPA entities.

Where should @Transactional be placed in a Spring application?

Place @Transactional on service layer methods, not repository methods. Use readOnly=true for query operations as an optimization, and choose propagation levels like REQUIRES_NEW only when an independent transaction is genuinely needed.

Does this Skill support Spring Boot 3 and Spring Security 6?

Yes, the patterns target Spring Boot 3.x and Spring 6.x, including SecurityFilterChain-based configuration, Jakarta validation annotations, and modern auto-configuration conventions. Java 17 or later is required.

Why is field injection considered an anti-pattern in Spring?

Field injection prevents final fields, allows instances to be created without dependencies, and requires reflection or a Spring context in unit tests. Constructor injection makes dependencies explicit, immutable, and easy to mock.

How do I handle exceptions globally in a Spring REST API?

Create a @RestControllerAdvice class with @ExceptionHandler methods for each domain exception, mapping them to consistent ErrorResponse bodies and correct HTTP status codes like 404, 409, and 400 for validation failures.