Dependency Injection with Spring
in 10 minutes
Corneil du Plessis
– You have some appreciation of component-oriented
– You have seen Java code
– You have heard of the Spring Framework or Dependency
● Take away
– Some appreciation for benefits of dependency injection
– Some understanding of how Spring supports dependency
What is Dependency Injection?
● Robert C Martin and Martin Fowler has written some of the best
articles on the subject.
● Dependency Injection is also known as Inversion of Control or
● DI is a specific form of IoC.
● When an object is composed the responsibility for composing the
dependents of the object is not handled by the specific object.
● Modern applications uses one or more containers or frameworks to
take care of DI.
● Examples are EJB container and Spring Framework.
● We will look at mechanisms provider by Spring Framework
What is Spring Framework?
● The Spring Framework provides support for a large
number of useful programming patterns.
● Patterns in questions are:
DI – Best Practice
● Required unchanging dependencies via constructor.
● Assemble and fail early
● Be careful of the cost of DI frameworks.
– Don't use to create Data Transfer Objects.