springboot-patterns

Implements Spring Boot REST APIs with layered services, JPA repositories, caching, and exception handling.

Updated Apr 18, 2026
One-click install
npx skills add https://github.com/JohnRebellion/.claude-public --skill springboot-patterns-johnrebellion
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: springboot-patterns
Source: https://github.com/JohnRebellion/.claude-public/tree/main/claude/skills/springboot-patterns
Command: npx skills add https://github.com/JohnRebellion/.claude-public --skill springboot-patterns-johnrebellion

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building production-grade Spring Boot backends requires consistent patterns for controllers, services, repositories, validation, caching, and error handling, and this Skill provides ready-to-apply code templates for all of them. ## Core Features & Use Cases - REST API Structure: Thin controllers with pagination, DTO records with Bean Validation, and centralized exception handling via @ControllerAdvice. - Data & Service Layers: Spring Data JPA repositories, transactional services, caching with @Cacheable, and async processing with @Async. - Production Concerns: Rate limiting with Bucket4j (with secure X-Forwarded-For handling), request logging filters, retry with exponential backoff, and observability via Micrometer and OpenTelemetry. - Use Case: When scaffolding a new Spring Boot microservice, use this Skill to generate the controller-service-repository layers with validation, global error handling, and caching already wired correctly. ## Quick Start Ask the AI to create a Spring Boot REST endpoint for a new entity with validation, pagination, and centralized exception handling.

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?▼

Use thin @RestController classes that delegate to @Service classes, which in turn call Spring Data JPA repositories. Controllers handle HTTP concerns and DTO mapping, services hold business logic with @Transactional, and repositories stay as simple interfaces extending JpaRepository.

How to handle validation errors globally in Spring Boot?▼

Create a @ControllerAdvice class with an @ExceptionHandler for MethodArgumentNotValidException that collects field errors into a single message. Return a structured error body with HTTP 400, and add handlers for AccessDeniedException and generic Exception for 403 and 500 responses.

Does Spring Boot caching require extra configuration?▼

Yes, you must add @EnableCaching to a configuration class before annotations like @Cacheable and @CacheEvict take effect. Then annotate service methods with @Cacheable(value, key) to cache results and @CacheEvict to invalidate entries.

Why is X-Forwarded-For unsafe for rate limiting in Spring?▼

Clients can spoof the X-Forwarded-For header, so reading it directly lets attackers bypass IP-based rate limits. Only trust it behind a configured reverse proxy with server.forward-headers-strategy set and ForwardedHeaderFilter registered; otherwise use request.getRemoteAddr().

When should I use @Transactional readOnly in Spring Data JPA?▼

Use @Transactional(readOnly = true) on query-only service methods to signal the persistence provider that no writes occur, enabling optimizations like skipping dirty checking. Reserve read-write transactions for methods that create, update, or delete entities.