Skillshub spring-boot-best-practices
Core coding standards, dependency injection, and configuration for Spring Boot 3. Use when applying Spring Boot 3 coding standards or configuring dependency injection. (triggers: application.properties, **/*Service.java, autowired, requiredargsconstructor, configuration-properties, slf4j)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/spring-boot-best-practices" ~/.claude/skills/comeonoliver-skillshub-spring-boot-best-practices && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/spring-boot-best-practices/SKILL.mdsource content
Spring Boot Best Practices
Priority: P0
Implementation Guidelines
Dependency Injection (DI)
- Constructor Injection: ALWAYS use Constructor Injection for immutability. Use
(Lombok) to reduce boilerplate. Mark all dependencies as@RequiredArgsConstructor
.final - Avoid @Autowired: NEVER use field injection. It prevents unit testing without Spring context and hides dependencies.
Configuration & Data
- Type-Safe Config: Use
with Records (Java 17+) instead of@ConfigurationProperties
. Use Spring profile-specific files (e.g.,@Value
,application-dev.yml
) and set active profile viaapplication-prod.yml
. Never hardcode secret values in properties files.SPRING_PROFILES_ACTIVE - Validation: Combine with
and Jakarta Bean Validation (@Validated
,@NotNull
) to fail fast at startup. Use@NotEmpty
for structured configuration.application.yaml - DTOs: Use
as immutable DTOs to reduce boilerplate and ensure thread safety. Handle empty values withrecords
to avoidOptional
.NullPointerException
Observability & Quality
- Error Handling: Implement
and@ControllerAdvice
(RFC 7807) for standardized error responses.ProblemDetails - Logging: Use
withSLF4J
. Implement Structured Logging by logging arguments (@Slf4j
).log.info("id: {}", id) - Tooling: Mandate
orSpotless
for code formatting. UseCheckstyle
to manage JDK 21+ versions.sdkman
Anti-Patterns
- No @Autowired on fields: Use constructor injection via @RequiredArgsConstructor.
- No Setters on dependencies: Declare all injected fields as final.
- No context.getBean(): Inject dependencies via constructor DI.
- No log-and-swallow: Rethrow or handle exceptions explicitly.