springboot-patterns

Implements Spring Boot REST APIs, services, data access, caching, and async processing patterns.

Updated May 4, 2026
One-click install
npx skills add https://github.com/studenkov/FinanceTracker --skill springboot-patterns-studenkov
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: springboot-patterns
Source: https://github.com/studenkov/FinanceTracker/tree/main/.agents/skills/springboot-patterns
Command: npx skills add https://github.com/studenkov/FinanceTracker --skill springboot-patterns-studenkov

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building production-grade Spring Boot backends requires consistent decisions about layering, validation, error handling, caching, and concurrency. This Skill provides proven code patterns for each concern so you avoid ad-hoc implementations and common pitfalls like spoofable rate limiting or missing transaction boundaries. ## Core Features & Use Cases - REST API Structure: Thin controllers with constructor injection, pagination, DTO records, and Bean Validation annotations. - Data & Service Layers: Spring Data JPA repositories with custom queries, transactional services, and read-only query optimization. - Cross-Cutting Concerns: Global exception handling with @ControllerAdvice, SLF4J logging, request logging filters, caching with @Cacheable, and @Async processing. - Resilience & Security: Retry with exponential backoff, Bucket4j rate limiting with safe X-Forwarded-For handling, and observability via Micrometer and OpenTelemetry. - Use Case: When scaffolding a new market-tracking microservice, apply these patterns to stand up a validated REST endpoint backed by a transactional service, cached reads, and centralized error responses in one pass. ## Quick Start Ask the AI to build a Spring Boot REST endpoint with a service layer, JPA repository, validation, and global exception handling for your domain entity.

Frequently Asked Questions about springboot-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a Spring Boot REST API with layers?

Structure a Spring Boot API with thin @RestController classes delegating to @Service classes, which call Spring Data JPA repositories. Use constructor injection, DTO records for requests and responses, and keep business logic out of controllers.

How to handle validation errors globally in Spring Boot?

Use a @ControllerAdvice class with an @ExceptionHandler for MethodArgumentNotValidException to collect field errors into a single response. Spring Boot 3 also supports RFC 7807 problem details via spring.mvc.problemdetails.enabled=true.

How do I add caching to a Spring Boot service?

Enable caching with @EnableCaching on a configuration class, then annotate service methods with @Cacheable for reads and @CacheEvict for invalidation. Keys can reference method parameters, such as the entity ID.

Can I trust X-Forwarded-For for rate limiting in Spring?

X-Forwarded-For is spoofable and untrusted by default. Only rely on it behind a trusted proxy with server.forward-headers-strategy configured and ForwardedHeaderFilter registered; otherwise use request.getRemoteAddr() directly.

Why use constructor injection instead of field injection in Spring?

Constructor injection makes dependencies explicit, enables final fields, and simplifies unit testing without the Spring container. Field injection hides dependencies and complicates null-safety, so production code should prefer constructors.