Dependency Injection is a process, where objects define their dependencies. Suppose an object ‘obj1’ is using other objects obj2, obj3. In the source code, ‘obj1’ mention its dependencies obj2, obj3 through constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method.

What are the basic packages of Spring IOC?

a.org.springframework.beans

b.org.springframework.context

Spring IOC Container

org.springframework.context.ApplicationContext represents Spring IOC container and is responsible for creating and managing the beans. ApplicationContext Class uses configuration meta data, to manage these beans. You can supply this configuration metadata using any configuration file (like keeping the POJOs information in xml files), (or) by using Java Annotations.

Hello World Application

Suppose there is a POJO class that represent an Employee information. I am going to explain how to configure the metadata of Employee class in configuration file (myConfiguration.xml) and get the bean of Employee class using Spring IOC container.

Above statement loads the configuration metadata from the file ‘myConfiguration.xml’ file. You can supply as many configuration files as you want. ClassPathXmlApplicationContext look for the configuration files in application class path.

What is advantage of Dependency injection?

a.Decoupling of the dependencies makes your application more effective while in implementation and maintenance phases