# Spring Boot Best Practices

> Core coding standards, dependency injection, and configuration for Spring Boot 3

- Skill: `fierzone/spring-boot-best-practices` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add fierzone/spring-boot-best-practices`
- Raw SKILL.md: https://api.skillmd.com/api/skills/fierzone/spring-boot-best-practices/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: fierzone (https://skillmd.com/u/fierzone)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/fierzone/spring-boot-best-practices

---


# Spring Boot Best Practices

## **Priority: P0**

## Implementation Guidelines

### Dependency Injection (DI)

- **Constructor Injection**: ALWAYS use constructor injection (via `@RequiredArgsConstructor`) for immutability.
- **Final Fields**: Mark all dependencies as `final`.
- **Avoid @Autowired**: Do not use field injection. It hides dependencies.

### Configuration

- **Type-Safe Config**: Use `@ConfigurationProperties` with Records instead of `@Value`.
- **Validation**: Combine with `@Validated` and Jakarta constraints (`@NotNull`) to fail fast.
- **Externalization**: Follow strict precedence (Env vars > Config files).

### Observability & Logging

- **SLF4J**: Use `@Slf4j`. NEVER use `System.out`.
- **Structured Logging**: Log arguments (`log.info("id: {}", id)`), not concatenated strings.

## Anti-Patterns

- **Field Injection**: `**No @Autowired on fields**: Use constructor injection.`
- **Mutable Components**: `**No Setters**: Use final fields.`
- **Manual Bean Lookup**: `**No context.getBean()**: Inject dependencies.`
- **Swallowed Exceptions**: `**No log-and-swallow**: Rethrow or handle cleanly.`

## References

- [Implementation Examples](references/implementation.md)

