spring

Enforces Spring Boot layering, dependency injection, and transaction conventions for Java code generation.

Updated Sep 20, 2026
One-click install
npx skills add https://github.com/aascer39/codeagent --skill spring-aascer39
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: spring
Source: https://github.com/aascer39/codeagent/tree/main/.agents/skills/spring
Command: npx skills add https://github.com/aascer39/codeagent --skill spring-aascer39

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? AI-generated Spring Boot code often suffers from bloated Controllers, God-class Services, circular dependencies, hardcoded secrets, and misplaced transaction boundaries. This Skill gives AI agents a single, enforceable rulebook so every generated or refactored Spring component follows consistent layering and wiring conventions. ## Core Features & Use Cases - Layering & DI rules: Defines Controller → Service → Mapper responsibilities, constructor injection with final fields, semantic stereotype annotations, and explicit bans on field injection, ApplicationContext lookups, and @Lazy workarounds. - Transaction, exception & async governance: Specifies where @Transactional belongs, how to keep external calls (LLM, HTTP, approvals) out of transactions, unified @RestControllerAdvice error mapping with a fixed {"error": "..."} body, and thread-pool requirements for @Async. - Agent-specific guidance: Covers role-based Agent service decomposition, the mandatory Spring AI OpenAI-compatible ChatModel abstraction, CLI entry via ApplicationRunner with @ConditionalOnProperty, and terminal-charset handling for Chinese consoles. - Use Case: When an AI agent is asked to add a new REST endpoint to the CodeAgent project, it consults this Skill to place validation in the DTO, business logic in the Service, transactions at the use-case boundary, and errors in the global exception handler. ## Quick Start Ask the AI to create or refactor a Spring Boot Controller, Service, or configuration class and require it to follow the spring skill conventions.

Frequently Asked Questions about spring

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

FAQPage Schema
How do I structure a Spring Boot Controller and Service correctly?▼

Keep Controllers limited to request parsing, Bean Validation, and response mapping; all business rules, transactions, and Mapper coordination belong in the Service layer. The call chain must be Controller → Service → Mapper, with DTOs for API contracts instead of exposing Entities.

What is the recommended dependency injection style in Spring Boot?▼

Use constructor injection via Lombok @RequiredArgsConstructor with private final dependency fields. Field injection with @Autowired is not allowed as a default, and ApplicationContext.getBean() is reserved for dynamic plugin or framework infrastructure scenarios.

Where should @Transactional be placed in a Spring application?▼

Place @Transactional on public Service or use-case methods, never on Controller methods. Long external calls such as HTTP requests, LLM invocations, or human approvals must be moved outside the transaction to avoid holding database connections and locks.

How do I handle circular dependencies between Spring beans?▼

Analyze responsibilities, extract shared capabilities, and adjust the dependency direction, optionally introducing a coordinating domain service. Using @Lazy to hide a circular dependency is prohibited; it is only acceptable as an explicit technical solution.

Can I use DashScope-specific starters with Spring AI in this project?▼

No. The model layer must use the generic spring-ai-starter-model-openai with spring.ai.openai.* properties bound from environment variables. Business code injects the standard ChatModel abstraction, and switching providers only requires changing AI_BASE_URL and AI_MODEL in .env.

Why does @SpringBootTest hang when the app has a CLI runner?▼

ApplicationRunner and CommandLineRunner beans execute during @SpringBootTest and can block reading stdin. Guard the CLI runner with @ConditionalOnProperty such as codeagent.cli-enabled and set it to false in the test profile.