Provides Spring Boot dependency injection patterns using constructor-first design, ObjectProvider for optionals, @Primary/@Qualifier for bean selection, and wiring validation. Use for services/configs, refactoring field injection, or fixing ambiguous wiring.
From developer-kit-javanpx claudepluginhub giuseppe-trisciuoglio/developer-kit --plugin developer-kit-javaThis skill is limited to using the following tools:
references/examples.mdreferences/reference.mdreferences/spring-official-dependency-injection.mdSearches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
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:
@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.
@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.
@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.
@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