Spring is a container - Why and How?

  1. In Spring framework, the IOC container is represented by the interface ApplicationContext which holds all objects in a project, later we can ask ApplicationContext for any bean/object by using a method called “ getBean() ” we will see this later in details.

  2. The Spring container is responsible for instantiating, configuring and assembling objects known as beans, as well as managing their lifecycle.

  3. The Spring framework provides several implementations of the ApplicationContext interface

    1. ClassPathXmlApplicationContext

      This container loads the definitions of the beans from an XML file. Here you do not need to provide the full path of the XML file but you need to set CLASSPATH properly because this container will look like bean configuration XML file in CLASSPATH.

    2. FileSystemXmlApplicationContext for standalone applications

      This container loads the definitions of the beans from an XML file. Here you need to provide the full path of the XML bean configuration file to the constructor.

    3. WebApplicationContext for web applications.

      This container loads the XML file with definitions of all beans from within a web application.

  4. In order to assemble beans, the container uses configuration metadata, which can be in the form of XML configuration or annotations.