Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Spring IoC container


May 14, 2021 Spring


Table of contents


IoC container

Spring containers are at the heart of the Spring framework. C ontainers create objects, connect them together, configure them, and manage their entire lifecycle from creation to destruction. S pring containers use dependency injection (DI) to manage the components that make up an application. T hese objects are called Spring Beans, and we'll discuss them in the next chapter.

By reading the instructions provided by configuration metadata, containers know which objects are instantiated, configured, and assembled. C onfiguration metadata can be represented by XML, Java comments, or Java code. T he following image is a high-level view of how Spring works. Spring IoC containers leverage Java's POJO classes and configuration metadata to generate fully configured and executable systems or applications.

AN IOC container Has a container that relies on injection to create objects, and an IOC container is responsible for instantiation, positioning, configuring objects in an application, and establishing dependencies between those objects. U sually a new instance, control is controlled by the programmer, and "control inverse" means that the new instance work is not done by the programmer but by the Spring container. In Spring, BeanFactory is the actual representative of the IOC container.

Spring IoC container

Spring provides two different types of containers.

Serial number Containers and descriptions
1 Spring Bean Factory container

It is the simplest container that provides basic support for DI, defined by the org.springframework.beans.factory.BeanFactory interface. BeanFactory or related interfaces such as BeanFactoryAware, InitializingBean, DisposableBean, still have a number of reverse compatibility purposes in Spring with a number of third-party frameworks integrated with Spring.

2 Spring ApplicationContext container

The container adds more enterprise-specific features, such as the ability to parse text information from a property file, and the ability to publish application events to event listeners of interest. The container is defined by the org.springframework.context.ApplicationContext interface.

ApplicationContext containers include all the features of the BeanFactory container, so it is generally not recommended to use BeanFactory. BeanFactory can still be used for lightweight applications, such as mobile devices or applet-based applications, where the amount and speed of its data is significant.