Chapter 1: Dependency Injection - AyadiAkrem/Spring-5-Training GitHub Wiki

This chapter covers the Spring Framework implementation of the Inversion of Control (IoC) [1] principle. IoC is also known as dependency injection (DI).

The basic packages for Spring framework's IoC are:

  • org.springframework.beans : The main interface in this package is the BeanFactory in org.springframework.beans.factory packages, it provides an advanced configuration mechanism capable of managing any type of object

  • org.springframework.context : The main interface in this package is the ApplicationContext, it is a central interface to provide configuration for an application. it provides:

    • Bean factory methods for accessing application components Inherited from ListableBeanFactory.
    • The ability to load file resources in a generic fashion. Inherited from the ResourceLoader interface.
    • The ability to publish events to registered listeners. Inherited from the ApplicationEventPublisher interface.
    • The ability to resolve messages, supporting i18n. Inherited from the MessageSource interface.
    • The ability to integrate the Spring's AOP features.

    In addition to standard BeanFactory lifecycle capabilities, ApplicationContext implementations detect and invoke ApplicationContextAware beans as well as ResourceLoaderAware, ApplicationEventPublisherAware and MessageSourceAware beans.