spring-boot-best-practices

Apply 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)

385 stars

Best use case

spring-boot-best-practices is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Apply 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)

Teams using spring-boot-best-practices should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/spring-boot-best-practices/SKILL.md --create-dirs "https://raw.githubusercontent.com/HoangNguyen0403/agent-skills-standard/main/skills/spring-boot/spring-boot-best-practices/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/spring-boot-best-practices/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How spring-boot-best-practices Compares

Feature / Agentspring-boot-best-practicesStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Apply 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)

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Spring Boot Best Practices

## **Priority: P0**

## Implementation Guidelines

### Dependency Injection (DI)

- **Constructor Injection**: ALWAYS use **Constructor Injection** for immutability. Use **`@RequiredArgsConstructor`** (Lombok) to reduce boilerplate. Mark all dependencies as **`final`**.
- **Avoid @Autowired**: NEVER use field injection. It prevents unit testing without Spring context and hides dependencies.

### Configuration & Data

- **Type-Safe Config**: Use `@ConfigurationProperties` with Records (Java 17+) instead of `@Value`. Use Spring profile-specific files (e.g., `application-dev.yml`, `application-prod.yml`) and set active profile via `SPRING_PROFILES_ACTIVE`. Never hardcode secret values in properties files.
- **Validation**: Combine with **`@Validated`** and **Jakarta Bean Validation** (`@NotNull`, `@NotEmpty`) to fail fast at startup. Use **`application.yaml`** for structured configuration.
- **DTOs**: Use **`records`** as immutable **DTOs** to reduce boilerplate and ensure thread safety. Handle empty values with **`Optional`** to avoid `NullPointerException`.

### Observability & Quality

- **Error Handling**: Implement **`@ControllerAdvice`** and **`ProblemDetails` (RFC 7807)** for standardized error responses.
- **Logging**: Use **`SLF4J`** with **`@Slf4j`**. Implement **Structured Logging** by logging arguments (`log.info("id: {}", id)`).
- **Tooling**: Mandate **`Spotless`** or **`Checkstyle`** for code formatting. Use **`sdkman`** to manage JDK 21+ versions.

## 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.

## References

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

Related Skills

swift-best-practices

385
from HoangNguyen0403/agent-skills-standard

Apply Guard, Value Types, Immutability, and Naming conventions in Swift. Use when writing idiomatic Swift using guard, value types, immutability, or naming conventions. (triggers: **/*.swift, guard, let, struct, final)

spring-boot-testing

385
from HoangNguyen0403/agent-skills-standard

Write unit, integration, and slice tests for Spring Boot 3 applications. Use when writing unit tests, integration tests, or slice tests for Spring Boot 3 applications. (triggers: **/*Test.java, webmvctest, datajpatest, testcontainers, assertj)

spring-boot-security

385
from HoangNguyen0403/agent-skills-standard

Configure Spring Security 6+ with Lambda DSL, JWT, and hardening rules. Use when configuring Spring Security 6+, OAuth2, JWT, or security hardening in Spring Boot. (triggers: **/*SecurityConfig.java, **/*Filter.java, security-filter-chain, lambda-dsl, csrf, cors)

spring-boot-scheduling

385
from HoangNguyen0403/agent-skills-standard

Configure scheduled tasks and distributed locking with ShedLock in Spring Boot. Use when implementing @Scheduled tasks or distributed locking with ShedLock in Spring Boot. (triggers: **/*Scheduler.java, **/*Job.java, scheduled, shedlock, cron)

spring-boot-observability

385
from HoangNguyen0403/agent-skills-standard

Instrument Spring Boot with Micrometer metrics, distributed tracing, and structured logging. Use when adding Micrometer metrics, distributed tracing, or structured logging to Spring Boot. (triggers: logback-spring.xml, application.properties, micrometer, tracing, correlation-id, mdc)

spring-boot-microservices

385
from HoangNguyen0403/agent-skills-standard

Standards for Feign clients and asynchronous messaging with Spring Cloud Stream. Use when implementing Feign HTTP clients or async event messaging in Spring Boot microservices. (triggers: **/*Client.java, **/*Consumer.java, feign-client, spring-cloud-stream, rabbitmq, resilience4j)

spring-boot-deployment

385
from HoangNguyen0403/agent-skills-standard

Deploy Spring Boot apps with Docker, GraalVM native images, and graceful shutdown. Use when deploying Spring Boot apps as GraalVM native images, containers, or configuring shutdown. (triggers: Dockerfile, compose.yml, docker-layer, native-image, graceful-shutdown)

spring-boot-data-access

385
from HoangNguyen0403/agent-skills-standard

Optimize JPA, Hibernate, and database interactions in Spring Boot. Use when implementing JPA entities, repositories, or database access in Spring Boot. (triggers: **/*Repository.java, **/*Entity.java, jpa-repository, entity-graph, transactional, n-plus-1)

spring-boot-architecture

385
from HoangNguyen0403/agent-skills-standard

Structure Spring Boot 3+ projects with feature packaging and clean layering. Use when structuring Spring Boot 3 projects, defining layers, or applying architecture patterns. (triggers: pom.xml, build.gradle, structure, layering, dto, controller, @RestController, @Service, @Repository, @Entity, @Bean, @Configuration)

spring-boot-api-design

385
from HoangNguyen0403/agent-skills-standard

Design Spring Boot APIs with OpenAPI, Versioning, and Global Error Handling. Use when designing Spring Boot APIs with OpenAPI specs, versioning, or global error handling. (triggers: **/*Controller.java, openapi, swagger, versioning, problemdetails)

php-best-practices

385
from HoangNguyen0403/agent-skills-standard

Write PHP following best practices, PSR standards, and code quality guidelines. Use when writing PHP following PSR standards, SOLID principles, or improving code quality. (triggers: **/*.php, psr-12, camelCase, PascalCase, dry, solid)

kotlin-best-practices

385
from HoangNguyen0403/agent-skills-standard

Core patterns for robust Kotlin code including scope functions and backing properties. Use when writing idiomatic Kotlin, choosing between scope functions (let/apply/run/also/with), encapsulating mutable state with backing properties, or exposing read-only collection interfaces. (triggers: **/*.kt, apply, let, run, also, with, runCatching, backing property, MutableList, internal, private set)