spring-boot
Production-grade Java framework with auto-configuration and embedded server for stand-alone applications.
Core Concepts
- Auto-configuration:
@EnableAutoConfigurationpulls in beans from classpath dependencies - JPA/Hibernate:
@EntitywithJpaRepositoryinterface for CRUD without boilerplate - REST controllers:
@RestControllerwith@RequestMappingfor JSON API endpoints - Spring Security:
SecurityFilterChainbean for authentication and authorization rules
Common Patterns
- Actuator:
/actuator/health,/actuator/metricsfor production observability and monitoring - Profiles:
application-dev.yml/application-prod.ymlfor environment-specific config - Testing:
@WebMvcTestwithMockMvcfor controller-layer testing,@DataJpaTestfor repos - Dependency injection:
@Autowiredor constructor injection with@Service/@Repositorybeans
Best Practices
- Prefer constructor injection over
@Autowiredfield injection for testability and immutability - Use
@Transactionalat the service layer, not the controller, for consistent transaction boundaries - Keep controllers thin: delegate business logic to
@Serviceclasses - Validate request bodies with
@Validand custom@Constraintannotations
Common Code Patterns
@RestController @RequestMapping("/api/users")with@GetMapping("/{id}")for RESTpublic interface UserRepo extends JpaRepository<User, Long>for auto-implemented CRUD