Spring Source Code Analysis: the problem of creating spring ioc Container in web Environment

ContextLoader methods in the class

   

the ApplicationContext of Spring in this picture has two subclasses WebApplicationContext and ConfragubleApplicationContext . What"s the difference between them?

May.22,2021

if you look through the relevant Javadoc, you can know:

Central interface to provide configuration for an application. This is read-only while the application is running, but may be reloaded if the implementation supports this.
An ApplicationContext provides:

Bean factory methods for accessing application components. Inherited from ListableBeanFactory.

  • The ability to load file resources in a generic fashion. Inherited from the ResourceLoader interface.
  • The ability to publish events to registered listeners. Inherited from the ApplicationEventPublisher interface.
  • The ability to resolve messages, supporting internationalization. Inherited from the MessageSource interface.
  • Inheritance from a parent context. Definitions in a descendant context will always take priority. This means, for example, that a single parent context can be used by an entire web application, while each servlet has its own child context that is independent of that of any other servlet.

In addition to standard BeanFactory lifecycle capabilities, ApplicationContext implementations detect and invoke ApplicationContextAware beans as well as ResourceLoaderAware, ApplicationEventPublisherAware and MessageSourceAware beans.
-- ApplicationContext (Spring Framework 5.0.8.RELEASE API)

the fourth point mentions the concept of parent context , that is, the Spring container supports multiple contexts, with the current context as the first priority, and those that are not configured are configured through the parent context.

Please refer to the document for other questions by yourself:

Menu