Spring IoC container

In Spring, the org.springframework.beans.factory.BeanFactory interface defines the basic IoC container, while the org.springframework.context.ApplicationContext interface represents an advanced IoC container. ApplicationContext is a super set of BeanFactory. It provides some additional enterprise-level functionalities on top of basic IoC features by BeanFactory

To cater for different types of applications, Spring provides various implementations of ApplicationContext out of the box. For standalone applications, you can use the FileSystemXmlApplicationContext or ClassPathXmlApplicationContext class. They are both implementations of ApplicationConext.

While working with Spring, you need to pass one XML file as an entry point for these containers. This file is called the Spring Application Context file. When the Spring container starts, it loads this XML file and starts configuring your beans (either with XML-based bean definition in this file, or annotation-based definition in your POJO Java class).

  • FileSystemXmlApplicationContext: This container loads the Spring XML file and processes it. You need to give the full path of the XML file.
  • ClassPathXmlApplicationContext: This container works similarly to FileSystemXmlApplicationContext; however, it assumes that the Spring XML file is available in CLASSPATH. You do not need to pass a root-level path for it.
  • WebXmlApplicationContext: This container is generally used within web applications. 

Spring's IoC container is responsible for instantiating, configuring, maintaining, and accumulating the beans (objects in your application). You need to provide configuration metadata about the objects you want to assemble with the IoC container. The following diagram depicts a high-level flow of how the IoC container gets this work done:

We provide Pojo Classes (or bean definitions) and Configuration metadata (set of instructions) as an input. The Spring IoC container will create and manage the objects (or beans) in a way that they produce a ready-to-use system. In short, an IoC container performs all low-level tasks (of managing beans and dependencies) so that you can write business logic in your POJO class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.8.8