java-spring-boot-patterns

Generates Spring Boot controllers, services, repositories, DTOs, and exception handlers following layered architecture conventions.

Updated Apr 20, 2020
One-click install
npx skills add https://github.com/UnterrainerInformatik/java-rdb-utils --skill java-spring-boot-patterns-unterrainerinformatik
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: java-spring-boot-patterns
Source: https://github.com/UnterrainerInformatik/java-rdb-utils/tree/main/.agents/skills/java-spring-boot-patterns
Command: npx skills add https://github.com/UnterrainerInformatik/java-rdb-utils --skill java-spring-boot-patterns-unterrainerinformatik

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Developers building Spring Boot applications often produce inconsistent code with business logic leaking into controllers, entities exposed directly in APIs, and missing exception handling. This Skill provides proven patterns and templates for structuring Spring Boot projects correctly from the start. ## Core Features & Use Cases - Layered Architecture Templates: Ready-to-use code patterns for controllers, services (interface + implementation), JPA repositories, and DTOs with MapStruct mappers. - Exception Handling & Configuration: Global exception handler with @RestControllerAdvice, custom exceptions, and profile-based configuration with @ConfigurationProperties. - Testing Patterns: MockMvc controller tests, Mockito service tests, and Testcontainers integration tests. - Use Case: When asked to "create a UserController with CRUD endpoints", the Skill generates a REST controller with versioned routes, proper status codes, validation, and a matching service layer. ## Quick Start Ask the AI to create a Spring Boot REST controller with service layer and global exception handling for your entity.

Frequently Asked Questions about java-spring-boot-patterns

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

FAQPage Schema
How do I structure a Spring Boot project with layered architecture?▼

Organize code into controller, service, repository, model, dto, exception, and config packages under your base package. Controllers handle HTTP, services contain business logic with @Transactional, and repositories extend JpaRepository for data access.

How to create a REST controller in Spring Boot with proper status codes?▼

Annotate the class with @RestController and @RequestMapping with a versioned path like /api/v1/users. Return ResponseEntity with 200 for reads, 201 with a Location header for creates, and 204 for deletes, using constructor injection for the service.

Should Spring Boot controllers return entities or DTOs?▼

Controllers should return DTOs, never entities, to avoid exposing internal model structure. Use Java records for request and response DTOs with validation annotations, and MapStruct mappers to convert between entities and DTOs.

How do I handle exceptions globally in Spring Boot?▼

Create a class annotated with @RestControllerAdvice containing @ExceptionHandler methods for each exception type. Return a consistent ErrorResponse record with a code and message, mapping custom exceptions like ResourceNotFoundException to appropriate HTTP statuses.

What is the difference between @WebMvcTest and @SpringBootTest?▼

@WebMvcTest loads only the web layer with mocked services for fast controller tests using MockMvc. @SpringBootTest starts the full application context for integration tests, often combined with Testcontainers for a real database.

When should I use native queries in Spring Data JPA?▼

Use native queries sparingly, only when derived queries or JPQL @Query cannot express the logic. Prefer derived query methods and existsBy checks, and use @EntityGraph to optimize fetching instead of writing native SQL.