Skip to content

Instantly share code, notes, and snippets.

@bdkosher
Last active October 1, 2019 16:30
Show Gist options
  • Save bdkosher/df76885ddcf4b47df978747bb20fe12e to your computer and use it in GitHub Desktop.
Save bdkosher/df76885ddcf4b47df978747bb20fe12e to your computer and use it in GitHub Desktop.
Constructor Injection that feels like Field Injection. Lombok generates a constructor for all final fields.
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class SomeBean {
private final SomeDependency someDependency;
private final OtherDependency otherDependency;
// Lombok auto-generates a two-arg constructor that Spring uses to inject dependencies
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment