In Java we have 4 access modifiers that can be applied to methods and fields of a class. In descending order of visibility, they are:
public String publicModifier = "Anyone can access me"; protected String protectedModifier = "Only accessible to classes in the same package as me, and my subclasses"; String defaultModifier = "Only accessible to classes in the same package as me"; private String privateModifier = "Only accessible within this class"; This article is a love letter to the third in this list of modifiers, the one-who-shall-not-be-named.
Spring developers will be familiar with its powerful Dependency Injection API. It allows you to declare @Beans that Spring then instantiates and manages. Any dependencies between these beans is then resolved by Spring and injected automagically.
Three Annotation-based Injection Patterns There are three ways Spring lets you declare the dependencies of your class using annotations:
Field injection (The bad)
import org.springframework.beans.factory.annotation.Autowired; public class MyBean { @Autowired private AnotherBean anotherBean; //Business logic.