Skip to content

Instantly share code, notes, and snippets.

@bdkosher
Created January 3, 2019 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdkosher/2fd419be13799747e3a7aa52df0d4793 to your computer and use it in GitHub Desktop.
Save bdkosher/2fd419be13799747e3a7aa52df0d4793 to your computer and use it in GitHub Desktop.
Looks like field injection, behaves like constructor injection.

Spring (and likely other IoC frameworks) offer three dependency injection approaches:

  1. 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.
  2. 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)

Constructor injection vs. Setter or Field Injection

Spring bean configuration approaches: XML-based vs. Annotation-based vs. Programmatic (DSL)-based

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment