spring-framework-patterns
Apply Spring Framework best practices: dependency injection, transaction management, AOP for CIA services
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Spring Framework Patterns Skill
Purpose
Apply Spring Framework best practices for dependency injection, transactions, and aspect-oriented programming.
When to Use
- ✅ Creating Spring services and components
- ✅ Managing transactions
- ✅ Implementing cross-cutting concerns
- ✅ Configuring application context
Dependency Injection Patterns
@Service
public class PoliticianService {
private final PoliticianRepository repository;
private final AuditLogger auditLogger;
// Constructor injection (preferred)
public PoliticianService(
PoliticianRepository repository,
AuditLogger auditLogger) {
this.repository = repository;
this.auditLogger = auditLogger;
}
}
Transaction Management
@Service
@Transactional(readOnly = true)
public class VotingService {
@Transactional
public void recordVote(Vote vote) {
voteRepository.save(vote);
statisticsService.updateStats(vote);
auditLogger.log("VOTE_RECORDED", vote.getId());
}
}
Aspect-Oriented Programming
@Aspect
@Component
public class PerformanceMonitoringAspect {
@Around("@annotation(Monitored)")
public Object monitor(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
try {
return joinPoint.proceed();
} finally {
long duration = System.currentTimeMillis() - start;
log.info("Method {} took {}ms",
joinPoint.getSignature().getName(), duration);
}
}
}
References
- Spring Framework: https://docs.spring.io/spring-framework/reference/
- ARCHITECTURE.md
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-03-11
- Index updated
- 2026-03-11
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!