From developer-kit-java
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.
How this skill is triggered — by the user, by Claude, or both
Slash command
/developer-kit-java:spring-boot-dependency-injectionThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Provides constructor-first dependency injection patterns for Spring Boot:
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-layernpx claudepluginhub giuseppe-trisciuoglio/developer-kit --plugin developer-kit-javaProvides Spring Boot patterns and best practices for architecture (services, controllers, DI), database (JPA, Flyway, transactions), security (JWT, OAuth2), validation, error handling, testing (JUnit, Mockito), and caching.
Build production Spring Boot applications - REST APIs, Security, Data, Actuator
Generates Spring Boot 3.x configurations, REST controllers, Spring Security 6 auth, Spring Data JPA or MyBatis-Plus data access, and reactive WebFlux endpoints. Use for microservices, Java REST APIs, or reactive Java apps.