Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Provides dependency injection patterns for Spring Boot projects, including constructor-first design, optional collaborator handling, bean selection, and wiring validation. Use when creating services and configurations, replacing field injection, or troubleshooting ambiguous or fragile Spring wiring.
.claude/skills/giuseppe-trisciuoglio-spring-boot-dependency-injection/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 17% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 39% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 38% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 39% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 24% | 0% |
Provides constructor-first dependency injection patterns for Spring Boot:
ObjectProvider or no-op fallbacks@Primary and @QualifierUse this skill when:
@Service, @Component, @Repository, or @Configuration classFor each class, identify:
Mandatory collaborators belong in the constructor. Optional ones need an explicit strategy such as ObjectProvider, conditional beans, or a no-op implementation.
For application services and adapters:
finalA single constructor is usually enough; @Autowired is unnecessary in that case.
Good options include:
ObjectProvider<T> when lazy access is useful@ConditionalOnProperty or @ConditionalOnMissingBean when wiring should change by configurationAvoid nullable collaborators that leave runtime behavior ambiguous.
When multiple beans share the same type:
@Primary for the default implementation@Qualifier for named variantsIf selection rules become complex, move them into a dedicated configuration class instead of spreading them across services.
Use @Configuration and @Bean methods when:
Business services should not know how infrastructure collaborators are instantiated.
After writing a new service or configuration:
java @SpringBootTest @ContextConfiguration(classes = UserService.class) class UserServiceWiringTest { @Autowired UserService userService; @Test void serviceIsInstantiated() { assertNotNull(userService); } }
@SpringBootTest for container-wide wiring validation.Failures at step 1 indicate wiring issues before business logic is added.
java@Service public class UserService { private final UserRepository userRepository; private final EmailSender emailSender; public UserService(UserRepository userRepository, EmailSender emailSender) { this.userRepository = userRepository; this.emailSender = emailSender; } public User register(UserRegistrationRequest request) { User user = userRepository.save(User.from(request)); emailSender.sendWelcome(user); return user; } }
This class is easy to instantiate directly in a unit test with mocks.
java@Service public class ReportService { private final ReportRepository reportRepository; private final NotificationGateway notificationGateway; public ReportService( ReportRepository reportRepository, ObjectProvider<NotificationGateway> notificationGatewayProvider ) { this.reportRepository = reportRepository; this.notificationGateway = notificationGatewayProvider.getIfAvailable(NotificationGateway::noOp); } }
This keeps optional behavior explicit without leaking null handling through the rest of the class.
java@Configuration public class PaymentConfiguration { @Bean @Primary PaymentGateway stripeGateway() { return new StripePaymentGateway(); } @Bean @Qualifier("fallbackGateway") PaymentGateway mockGateway() { return new MockPaymentGateway(); } }
Use @Primary for the default path and @Qualifier only where a specific variant is required.
@Lazy.references/reference.mdreferences/examples.mdreferences/spring-official-dependency-injection.mdspring-boot-crud-patternsspring-boot-rest-api-standardsunit-test-service-layer| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 14,293 | 15,723 | +10% | 1 | 1 | 0% | 2,661 | 3,101 | +17% | 0 | 0 | — |
case-02 | fail→pass | 14,761 | 12,538 | -15% | 1 | 1 | 0% | 2,619 | 3,652 | +39% | 0 | 0 | — |
case-03 | pass→pass | 13,420 | 12,119 | -10% | 1 | 1 | 0% | 2,628 | 3,659 | +39% | 0 | 0 | — |
case-04 | pass→pass | 11,372 | 8,531 | -25% | 1 | 1 | 0% | 2,310 | 2,856 | +24% | 0 | 0 | — |
case-05 | pass→pass | 12,274 | 11,490 | -6% | 1 | 1 | 0% | 2,381 | 3,523 | +48% | 0 | 0 | — |
case-06 | pass→pass | 9,711 | 6,137 | -37% | 1 | 1 | 0% | 1,830 | 2,388 | +30% | 0 | 0 | — |
case-07 | pass→pass | 11,139 | 5,317 | -52% | 1 | 1 | 0% | 2,101 | 2,235 | +6% | 0 | 0 | — |
case-08 | pass→pass | 12,389 | 10,852 | -12% | 1 | 1 | 0% | 2,079 | 3,139 | +51% | 0 | 0 | — |
case-09 | pass→pass | 24,364 | 9,173 | -62% | 1 | 1 | 0% | 2,484 | 2,832 | +14% | 0 | 0 | — |
case-10 | fail→fail | 7,983 | 7,249 | -9% | 1 | 1 | 0% | 1,526 | 2,534 | +66% | 0 | 0 | — |
case-11 | fail→pass | 11,754 | 18,802 | +60% | 1 | 1 | 0% | 2,346 | 3,227 | +38% | 0 | 0 | — |
case-12 | pass→pass | 13,501 | 14,128 | +5% | 1 | 1 | 0% | 2,499 | 3,141 | +26% | 0 | 0 | — |
case-13 | pass→pass | 15,380 | 10,490 | -32% | 1 | 1 | 0% | 2,349 | 2,996 | +28% | 0 | 0 | — |
case-14 | pass→pass | 10,823 | 6,978 | -36% | 1 | 1 | 0% | 2,058 | 2,490 | +21% | 0 | 0 | — |
case-15 | pass→pass | 7,701 | 4,394 | -43% | 1 | 1 | 0% | 1,338 | 2,027 | +51% | 0 | 0 | — |
case-16 | pass→pass | 13,010 | 19,408 | +49% | 1 | 1 | 0% | 1,996 | 3,049 | +53% | 0 | 0 | — |
case-17 | pass→pass | 13,931 | 10,435 | -25% | 1 | 1 | 0% | 2,463 | 3,098 | +26% | 0 | 0 | — |
case-18 | pass→pass | 9,089 | 7,019 | -23% | 1 | 1 | 0% | 1,513 | 2,497 | +65% | 0 | 0 | — |
case-19 | pass→pass | 11,737 | 6,950 | -41% | 1 | 1 | 0% | 1,988 | 2,380 | +20% | 0 | 0 | — |
case-20 | pass→pass | 8,095 | 4,760 | -41% | 1 | 1 | 0% | 1,349 | 1,981 | +47% | 0 | 0 | — |
case-21 | pass→pass | 11,253 | 10,527 | -6% | 1 | 1 | 0% | 1,927 | 3,102 | +61% | 0 | 0 | — |
case-22 | pass→pass | 11,941 | 8,058 | -33% | 1 | 1 | 0% | 2,053 | 2,622 | +28% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +14 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.