What problem does it solve?
Many Spring Boot applications rely on hidden or mutable wiring patterns such as field injection and service locators that make units hard to test, brittle during refactors, and ambiguous when multiple implementations exist. This Skill promotes explicit, constructor-first wiring, clear handling of optional collaborators, deterministic bean configuration, and testing strategies that validate wiring before integration.
Core Features & Use Cases
- Constructor-first patterns: Encourage final fields and required-args constructors (or Lombok @RequiredArgsConstructor) so services are immutable and directly instantiable in unit tests.
- Optional collaborator handling: Recommend @Autowired(required = false), ObjectProvider<T>, or no-op defaults for optional beans to avoid NullPointerExceptions and enable feature toggles.
- Bean selection and conditional configuration: Use @Qualifier, @Primary, profiles, and conditional annotations to resolve ambiguity and provide environment-specific wiring.
- Validation and testing: Prefer direct instantiation with mocks for unit tests and add slice or integration tests only after constructor contracts are validated.
- Real-world use: Modernizing legacy modules by replacing field injection, wiring multi-implementation adapters, and creating deterministic fallbacks for feature-flagged components.
Quick Start
Implement constructor injection by declaring mandatory collaborators as final constructor parameters and replacing field injection with a required-args constructor.