spring

Spring Framework

Comprehensive Java application framework with dependency injection and AOP

Details

Language / Topic
javaJava
Category
framework
Compatible Frameworks
spring

Rules

balanced
- Use constructor injection (not `@Autowired` on fields) for all dependencies — it makes classes testable and immutable.
- Use Spring profiles (`@Profile`, `application-{profile}.yml`) to separate dev/staging/prod configuration — never use runtime `if` checks.
- Apply `@Transactional` on service methods, not on controllers or repositories — keep transaction boundaries at the business logic layer.
- Use `@RestControllerAdvice` with `@ExceptionHandler` methods for centralized error handling — return consistent error response DTOs.
- Use `@RestController` for REST APIs and `@Service` for business logic. Keep controllers thin.
- Use `application.yml` for configuration with Spring profiles for environment-specific overrides.
- Use `@Transactional` on service methods, not controllers or repositories.
- Use Spring Data repositories for CRUD — define custom queries with `@Query` only when needed.