Spring Boot Development
Spring Boot 3+ project setup (Initializr), REST controllers, Service layer patterns, Exception handling (@ControllerAdvice), Profiles and configuration, Bean validation, Async operations
Build production Spring Boot applications using REST controllers, service layer patterns, exception handling, configuration management, and async operations.
Process
- Project Setup – Use Spring Initializr or
scripts/scaffold.py --name myapp --group-id com.example.
- REST Controllers – Create
@RestController with HTTP methods, constructor injection, DTOs.
- Service Layer – Implement
@Service with @Transactional(readOnly = true) for reads, @Transactional for writes.
- Exception Handling – Add
@RestControllerAdvice with handlers for domain exceptions, MethodArgumentNotValidException, ConstraintViolationException, and generic Exception.
- Configuration – Use
application.yml with profiles (dev, prod), @ConfigurationProperties for type-safe config.
- Bean Validation – Add
@Valid on request bodies, use @NotBlank, @NotNull, @Size, etc. on DTOs.
- Async – Use
@EnableAsync and @Async for long-running operations.
Best Practices
- Use constructor injection instead of field injection
- Use
@Transactional(readOnly = true) for read operations
- Use DTOs for API requests/responses (never expose entities)
- Implement
@ControllerAdvice for global exception handling
- Use Bean Validation for input validation
- Configure profiles for different environments
- Use
@Async for long-running operations
- Follow RESTful conventions, use
ResponseEntity for proper HTTP status codes
Anti-Patterns
| Anti-Pattern |
Fix |
Field injection with @Autowired |
Use constructor injection |
| Exposing entities directly |
Use DTOs |
Missing @Transactional on writes |
Add @Transactional |
| Synchronous blocking operations |
Use @Async |
| Hardcoded configuration |
Use @ConfigurationProperties |
| No exception handling |
Implement @ControllerAdvice |
| Missing validation |
Add Bean Validation |
Not using readOnly = true on reads |
Add to read methods |
Bundled Resources
| Resource |
Purpose |
| Installation Guide |
5-minute guide: Setup and run |
| scripts/utils.py |
Project utilities |
| scripts/validate.py |
Verify project follows skill patterns |
| REST API Patterns |
references/spring-patterns.json |
When to Use
This skill should be used when strict adherence to the defined process is required.
Prerequisites
- Basic understanding of the agent factory context.
- Access to the necessary tools and resources.
1---2name: developing-spring-boot3description: Spring Boot 3+ project setup (Initializr), REST controllers, Service layer patterns, Exception handling (@ControllerAdvice), Profiles and configuration, Bean validation, Async operations4---5# Spring Boot Development67Spring Boot 3+ project setup (Initializr), REST controllers, Service layer patterns, Exception handling (@ControllerAdvice), Profiles and configuration, Bean validation, Async operations89Build production Spring Boot applications using REST controllers, service layer patterns, exception handling, configuration management, and async operations.1011## Process12131. **Project Setup** – Use Spring Initializr or `scripts/scaffold.py --name myapp --group-id com.example`.142. **REST Controllers** – Create `@RestController` with HTTP methods, constructor injection, DTOs.153. **Service Layer** – Implement `@Service` with `@Transactional(readOnly = true)` for reads, `@Transactional` for writes.164. **Exception Handling** – Add `@RestControllerAdvice` with handlers for domain exceptions, `MethodArgumentNotValidException`, `ConstraintViolationException`, and generic `Exception`.175. **Configuration** – Use `application.yml` with profiles (`dev`, `prod`), `@ConfigurationProperties` for type-safe config.186. **Bean Validation** – Add `@Valid` on request bodies, use `@NotBlank`, `@NotNull`, `@Size`, etc. on DTOs.197. **Async** – Use `@EnableAsync` and `@Async` for long-running operations.2021## Best Practices2223- Use constructor injection instead of field injection24- Use `@Transactional(readOnly = true)` for read operations25- Use DTOs for API requests/responses (never expose entities)26- Implement `@ControllerAdvice` for global exception handling27- Use Bean Validation for input validation28- Configure profiles for different environments29- Use `@Async` for long-running operations30- Follow RESTful conventions, use `ResponseEntity` for proper HTTP status codes3132## Anti-Patterns3334| Anti-Pattern | Fix |35|--------------|-----|36| Field injection with `@Autowired` | Use constructor injection |37| Exposing entities directly | Use DTOs |38| Missing `@Transactional` on writes | Add `@Transactional` |39| Synchronous blocking operations | Use `@Async` |40| Hardcoded configuration | Use `@ConfigurationProperties` |41| No exception handling | Implement `@ControllerAdvice` |42| Missing validation | Add Bean Validation |43| Not using `readOnly = true` on reads | Add to read methods |4445## Bundled Resources4647| Resource | Purpose |48|----------|---------|49| [Installation Guide](../../../../docs/setup/installation.md) | 5-minute guide: Setup and run |50| [scripts/utils.py](scripts/utils.py) | Project utilities |51| [scripts/validate.py](scripts/validate.py) | Verify project follows skill patterns |52| REST API Patterns | [references/spring-patterns.json](references/spring-patterns.json) |5354## When to Use55This skill should be used when strict adherence to the defined process is required.5657## Prerequisites58- Basic understanding of the agent factory context.59- Access to the necessary tools and resources.