Spring (and likely other IoC frameworks) offer three dependency injection approaches:
- Constructor-based - Spring injects dependencies as constructor arguments when instantiating a bean
Developers using Lombok with Spring can create annotation-configured beans easily with the Lombok
@RequiredArgsConstructor
annotation. - Setter-based - Spring creates a bean through its default calls setter methods to
@Component
@RequiredArgsConstructor
public class SomeComponent {
private final SomeDependency dependency;
}
This looks like field injection but it's actually constr
- Use annotations to configure their application context (the standard approach for Spring Boot applications)