spring-boot-patterns
Skill4 starsChanged 9 months agoMITView on GitHub
Spring Boot patterns including stereotype annotations, dependency injection, profiles, configuration properties, and actuator endpoints. Use when the user is building Spring Boot applications, configuring dependency injection, setting up profiles for different environments, using @ConfigurationProperties, or enabling actuator health checks. Trigger on any mention of Spring Boot, @Component, @Service, @Repository, Spring DI, Spring profiles, or actuator.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- decebals/claude-code-javatheir own version, first seen Sep 6, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- decebals/claude-code-java★ 747same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository78 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rules/agents.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/claude-initial-setup.mdcCursor rule
- parallel-task-executionSkill
- subagent-patternsSkill
- task-coordinationSkill
- agent-communicationSkill
- context-managementSkill
- multi-agent-orchestrationSkill
- deploy-strategiesSkill
- github-actions-guideSkill
- pipeline-patternsSkill
- anthropic-sdk-guideSkill
- prompt-engineeringSkill
- tool-use-patternsSkill
- automated-review-setupSkill
- pr-standardsSkill
- review-checklistSkill
- file-organizationSkill
- immutability-patternsSkill
- naming-conventionsSkill
- branching-strategySkill
- commit-conventionsSkill
- pr-workflowSkill
- migration-patternsSkill
- query-optimizationSkill
- schema-design-guideSkill
- error-tracingSkill
- log-analysisSkill
- systematic-debuggingSkill
- django-admin-customizationSkill
- django-orm-masterySkill
- drf-api-patternsSkill
- docker-compose-guideSkill
- dockerfile-best-practicesSkill
- multi-stage-buildsSkill
- express-error-handlingSkill
- middleware-patternsSkill
- rest-api-nodeSkill
- async-fastapiSkill
- dependency-injection-fastapiSkill
- pydantic-validationSkill
- concurrency-patterns-goSkill
- error-handling-goSkill
- idiomatic-goSkill
- automation-triggersSkill
- hook-recipesSkill
- pre-post-hooksSkill
- junit-testingSkill
- maven-gradle-guideSkill
- mcp-resource-patternsSkill
- mcp-server-creationSkill
- mcp-tool-designSkill
- context-optimizationSkill
- knowledge-persistenceSkill
- memory-patternsSkill
- caching-strategiesSkill
- lazy-loading-patternsSkill
- profiling-guideSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 26
Use the correct annotation for each architectural layer.
- Distinctive: line 67
Always use constructor injection.
- Distinctive: line 90
Use profiles to swap implementations and configuration per environment.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Spring Boot Patterns
Core patterns for building production-ready Spring Boot applications.
When to Use
- User is setting up a Spring Boot project
- User asks about @Component, @Service, @Repository usage
- User needs dependency injection patterns
- User is configuring profiles for dev/staging/prod
- User asks about externalized configuration or actuator
Core Patterns
Stereotype Annotations -- Layer Separation
Use the correct annotation for each architectural layer. Spring applies different behaviors to each.
@Repository // Data access -- translates persistence exceptions
public class UserRepository {
private final JdbcTemplate jdbc;
public UserRepository(JdbcTemplate jdbc) { this.jdbc = jdbc; }
public Optional<User> findById(Long id) {
return jdbc.query("SELECT * FROM users WHERE id = ?",
new BeanPropertyRowMapper<>(User.class), id).stream().findFirst();
}
}
@Service // Business logic -- transactional boundaries live here
public class UserService {
private final UserRepository userRepository;
public UserService(UserRepository userRepository) { this.userRepository = userRepository; }
@Transactional
public User createUser(CreateUserRequest request) {
return userRepository.save(new User(request.name(), request.email()));
}
}
@RestController // Web layer -- handles HTTP requests
@RequestMapping("/api/v1/users")
public class UserController {
private final UserService userService;
public UserController(UserService userService) { this.userService = userService; }
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public UserResponse createUser(@Valid @RequestBody CreateUserRequest request) {
return UserResponse.from(userService.createUser(request));
}
}Constructor Injection
Always use constructor injection. It makes dependencies explicit, supports immutability, and works with final fields. Avoid field injection with @Autowired.
@Service
public class OrderService {
private final OrderRepository orderRepository;
private final PaymentGateway paymentGateway;
private final NotificationService notificationService;
// Single constructor -- @Autowired is implicit, no annotation needed
public OrderService(
OrderRepository orderRepository,
PaymentGateway paymentGateway,
NotificationService notificationService) {
this.orderRepository = orderRepository;
this.paymentGateway = paymentGateway;
this.notificationService = notificationService;
}
}Profiles -- Environment-Specific Configuration
Use profiles to swap implementations and configuration per environment.
# application.yml -- shared defaults
spring:
application:
name: my-service
---
# application-dev.yml
spring:
datasource:
url: jdbc:h2:mem:devdb
driver-class-name: org.h2.Driver
jpa:
show-sql: true
---
# application-prod.yml
spring:
datasource:
url: jdbc:postgresql://${DB_HOST}:5432/${DB_NAME}
username: ${DB_USER}
password: ${DB_PASSWORD}
jpa:
show-sql: falseProfile-specific beans:
@Configuration
public class StorageConfig {
@Bean
@Profile("dev")
public StorageService localStorageService() {
return new LocalFileStorageService("/tmp/uploads");
}
@Bean
@Profile("prod")
public StorageService s3StorageService(S3Client s3Client) {
return new S3StorageService(s3Client);
}
}@ConfigurationProperties -- Type-Safe Configuration
Bind external configuration to strongly-typed POJOs. Prefer this over scattered @Value annotations.
@ConfigurationProperties(prefix = "app.mail")
public record MailProperties(
String host,
int port,
String fromAddress,
Duration timeout,
RetryProperties retry
) {
public record RetryProperties(int maxAttempts, Duration delay) {}
}app:
mail:
host: smtp.example.com
port: 587
from-address: noreply@example.com
timeout: 5s
retry:
max-attempts: 3
delay: 2sEnable it:
@SpringBootApplication
@EnableConfigurationProperties(MailProperties.class)
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}Actuator -- Production Monitoring
Expose health checks, metrics, and application info for monitoring systems.
# application.yml
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus
endpoint:
health:
show-details: when-authorized
health:
db:
enabled: true
redis:
enabled: trueCustom health indicator:
@Component
public class PaymentGatewayHealthIndicator implements HealthIndicator {
private final PaymentGateway gateway;
public PaymentGatewayHealthIndicator(PaymentGateway gateway) { this.gateway = gateway; }
@Override
public Health health() {
try {
return gateway.ping()
? Health.up().withDetail("gateway", "reachable").build()
: Health.down().withDetail("gateway", "unreachable").build();
} catch (Exception e) { return Health.down(e).build(); }
}
}Anti-Patterns
- Field injection with @Autowired -- Makes dependencies hidden, prevents immutability, and breaks testing. Use constructor injection instead.
- Business logic in controllers -- Controllers should only handle HTTP concerns (request parsing, response formatting). Delegate to services.
- Catching all exceptions in controllers -- Use
@ControllerAdvicewith@ExceptionHandlerfor centralized exception handling. - Using @Component for everything -- Use the specific stereotype (@Service, @Repository, @Controller) so Spring applies the correct behavior (transaction proxies, exception translation).
- Hardcoding configuration values -- Use @ConfigurationProperties or environment variables. Never hardcode URLs, credentials, or environment-specific values.
Quick Reference
Stereotype annotations:
@Component -- Generic Spring-managed bean
@Service -- Business logic layer
@Repository -- Data access layer (exception translation)
@Controller -- Web layer (returns views)
@RestController -- Web layer (returns JSON)
Configuration:
@ConfigurationProperties -- Type-safe config binding
@Value("${key}") -- Single value injection
@Profile("dev") -- Environment-specific bean
Actuator endpoints:
/actuator/health -- Application health
/actuator/info -- Application info
/actuator/metrics -- Micrometer metrics
/actuator/prometheus -- Prometheus-format metricsDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

