lishman levelup
«previous  next»

Getting Started
Form Processing
IoC Container

Hibernate ORM

The Spring Inversion of Control Container

Spring promotes loose coupling of components, using the Spring Inversion of Control (IoC) container.

Objects in the application are assembled and managed by Spring, using Dependency Injection (DI). So, instead of creating their own dependencies using the new operator, or looking up dependencies using JNDI, objects are given their dependencies by the Spring IoC container, when they are instantiated. In other words, Spring uses DI to 'wire up' all the different components which go to make up our application.

The main benefit of DI is loose coupling. If an object accesses a dependency using its interface, then the implementation of this interface can be managed by the Spring IoC container, and injected into the object during instantiation. This way, different implementations can be injected, just by making a change to the configuration. For example, we could switch between local and remote services or substitute mock implementations, without the receiving object even being aware.