springboot-patterns

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

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill springboot-patterns-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: springboot-patterns
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/springboot-patterns
Command: npx skills add https://github.com/Femad-6/my-skills --skill springboot-patterns-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building production-grade Spring Boot backends requires consistent patterns for REST API design, layered architecture, data access, caching, and error handling, which are easy to get wrong or implement inconsistently across a codebase. ## Core Features & Use Cases - REST API Structure: Provides controller patterns with pagination, validation, DTO records, and constructor injection for Spring MVC and WebFlux. - Data & Service Layers: Covers Spring Data JPA repositories, transactional services, caching with @Cacheable, and async processing with @Async. - Production Hardening: Includes global exception handling with @ControllerAdvice, Bucket4j rate limiting with secure proxy header guidance, SLF4J logging, and Micrometer observability. - Use Case: When scaffolding a new Spring Boot microservice, use this Skill to generate a thin controller, transactional service, JPA repository, and centralized error handler that follow consistent conventions. ## Quick Start Ask the AI to create a Spring Boot REST endpoint for a resource with a service layer, JPA repository, validation, and global 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?

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

How to handle exceptions globally in Spring Boot?

Use @ControllerAdvice with @ExceptionHandler methods to centralize error handling for validation failures, access denied errors, and unexpected exceptions. 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. Specify cache names and keys, such as the entity ID, to control cache behavior.

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

No, X-Forwarded-For is spoofable unless your app sits behind a trusted proxy configured to overwrite it. Register ForwardedHeaderFilter and set server.forward-headers-strategy so request.getRemoteAddr() returns the real client IP safely.

Why use constructor injection instead of field injection in Spring?

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