Spring Boot-3-AbstractApplicationContext

AbstractApplicationContext is the first implementer of application context, and it is still defined as abstract. The reason why it is defined as abstract is that it does not need to be instantiated and cannot be directly aggregated by other classes (his subclasses can).

Since January 21, 2001
It is an abstract implementation of the org.springframework.context.ApplicationContext interface and does not hold stored configuration. Simply implement the functions of a public application context. Use template design patterns to require specific subclasses to implement abstract methods.

Compared to an empty BeanFactory, an ApplicationContext should detect special beans in its internal bean factory: therefore, these beans are automatically registered
org.springframework.beans.factory.config.BeanFactoryPostProcessor
org.springframework.beans.factory.config.BeanPostProcessor
org .springframework.context.ApplicationListener
are all defined as beans in context.

An org.springframework.context.MessageSource is also provided to the context, named messageSource. Additionally, message resolution is delegated to the parent context. At the same time, a multicaster named applicationEventMulticaster is provided as a bean in the context and provides a default implementation of SimpleApplicationEventMulticaster.

1. The parent-child relationship of containers

There is a member variable in AbstractApplicationContext:

	@Nullable
	private ApplicationContext parent;

Used to represent its parent application context. This is also Spring's design. When Spring Boot starts, two application contexts will be created. The parent application context is used to load Spring beans. The subcontainer is used to load application beans. The child can access the parent. The parent The child is not accessed.

Guess you like

Origin blog.csdn.net/tales522/article/details/132843471