Beans objects form the backbone of your application and are managed by the Spring IoC container.
It is instantiated, assembled, and managed by a Spring IoC container.
It is created with the help of the configuration metadata that you supply to the container.
Bean Scopes –
singleton – It limits the scope of the bean definition to a single instance per Spring IoC container (default).
prototype – It limits the scope of a single bean definition to have any number of object instances.
request – It limits the scope of a bean definition to an HTTP request.
session – It limits the scope of a bean definition to an HTTP session.
global-session – It 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 used to 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 – It is achieved when the spring container invokes the class constructor along with some arguments, each argument representing a dependency on the other class.
Setter-based – It is achieved when after invoking a no-argument constructor or no-argument static factory method, then 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 – This container provides the basic support for DI and is defined by the org.springframework.beans.factory.BeanFactory interface.
ApplicationContext – This container 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.