Dependency injection (Inversion of Control) in Spring framework
In this article we are going to learn about one of the foundational pieces of the Spring Framework; its implementation of Dependency Injection (which they usually refer by the more confusing name: Inversion of Control or IoC).
If you don’t know what Dependency Injection is, you can start by reading the first section of my Dependency Injection with Dagger and Bazel article. That section explains what is dependency injection and how it’s typically used.
Spring Beans
The term bean
is used to refer to a few things in the Java world, so it’s important to know what it means when used in the context of Spring.
A Spring bean
refers to an object that is injected by Spring’s depedency injection framework (Usually referred as IoC framework or IoC container).
ApplicationContext
The ApplicationContext
interface takes care of creation and injection of beans. There are different implementations of this interface that allow us to configure our beans using different methods. We’ll start by looking at the traditional way: ClassPathXmlApplicationContext
.