Beans
- Bean object forms the backbone of your application.
- Spring IoC container is responsible for instantiating, assembling, and managing the beans.
- Creation of beans takes place with the help of the configuration metadata that you supply to the container.
- Bean Scopes :
- singleton limits the scope of the bean definition to a single instance per Spring IoC container (default).
- prototype limits the scope of a single bean definition to have any number of object instances.
- request limits the scope of a bean definition to an HTTP request.
- session limits the scope of a bean definition to an HTTP session.
- global-session limits the scope of a bean definition to a global HTTP session.
Dependency Injection –
- It is a technique whereby one object (or static method) supplies the dependencies of another object.
- It is a design pattern that helps us implement IoC.
- This technique allows the creation of dependent objects outside of a class and provides those objects to a class in different ways.
- It helps to move the creation and binding of the dependent objects outside of the class that depends on them.
- Types of DI :
- Constructor-based DI is a dependency injection where the spring container invokes the class constructor along with some arguments, each argument representing a dependency on the other class.
- Setter-based DI is a dependency injection where after invoking a no-argument constructor or no-argument static factory method, the spring container calls the setter methods on the bean to instantiate the bean.
IOC Containers –
- The Spring or IOC container is the core of the Spring Framework.
- It will create the objects, wire them together, configure them, and manage their complete life cycle from creation till destruction.
- The container will get instructions on what objects to instantiate, configure, and assemble by reading the configuration metadata provided.
- It makes use of Java POJO classes and configuration metadata to produce a fully configured and executable system or application.
- Types of a container –
- BeanFactory provides the basic support for DI and is defined by the org.springframework.beans.factory.BeanFactory interface.
- ApplicationContext is defined by the org.springframework.context.ApplicationContext interface. It adds more enterprise-specific functionality. For instance, it resolves textual messages from a properties file and publishes the application events to interested event listeners.

