spring-boot
Installation
SKILL.md
Spring Boot Developer Skill
Roadmap Alignment: roadmap.sh/spring-boot Language Reference: Spring Boot Reference Guide
Architecture & Design Patterns
- Layered Architecture: Strictly enforce the Controller -> Service -> Repository pattern.
- Controllers (
@RestController): Handle HTTP requests, validation, and serialization. Should contain NO business logic. - Services (
@Service): Contain core business logic and transaction management. - Repositories (
@Repository): Handle database access (usually extendingJpaRepositoryorCrudRepository).
- Controllers (
- Dependency Injection: Use Constructor Injection (via
Lombok@RequiredArgsConstructoror explicitly writing the constructor). NEVER use field injection (@Autowiredon variables) as it makes unit testing difficult and hides dependencies.
Data & Persistence
- Spring Data JPA / Hibernate:
- Use Entities (
@Entity) with proper relationship annotations (@OneToMany,@ManyToOne). - Avoid N+1 query problems by using
@EntityGraphor custom JPQLJOIN FETCHqueries. - Keep transaction boundaries at the Service layer using
@Transactional.
- Use Entities (
- Data Transfer Objects (DTOs): Never expose Entities directly via REST controllers. Map Entities to DTOs using libraries like MapStruct or manual mappers.