Spring Boot

Beans

  • Bean is an object and is managed by the Spring IoC container.
  • It also forms the backbone of your application.
  • Spring IoC container instantiates, assembles, and otherwise manages bean.
  • Creation of beans is done with the help of configuration metadata that we supply to the container.
  • Bean Scopes –
    1. singleton
      • This limits the scope of a bean definition to a single instance per Spring IoC container (default).
    2. prototype 
      • This limits the scope of a single bean definition to have any number of object instances.
    3. request 
      • This limits the scope of a bean definition to an HTTP request.
    4. session 
      • This limits the scope of a bean definition to an HTTP session.
    5. global-session 
      • This 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.
  • Dependency Injection is responsible for the creation of dependent objects outside of a class. It also 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 –
    1. Constructor-based
      • It is achieved when the class constructor is invoked by the spring container along with some arguments, where each argument is representing a dependency on the other class.
    2. 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 creates the objects, wire them together, configure them, and manage their complete life cycle from creation till destruction.
  • The container gets its instructions with the help of the configuration metadata provided, about what objects to instantiate, configure, and assemble.
  • It makes use of Java POJO classes and configuration metadata to produce a fully configured and executable system or application.
  • Types of a container :
    1. BeanFactory
      • This container provides the basic support for DI and is defined by the org.springframework.beans.factory.BeanFactory interface.
    2. 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.
Scroll to Top