An overview of the

Spring is one of our most commonly used frameworks, so let’s take a look at the process of starting Spring. First of all, the Spring startup process is divided into 12 steps, including the completion of container initialization, the completion of the creation of a single instance of non-lazily loaded beans, the assignment injection and initialization of Bean properties, and the creation of the dispatcer and the triggering of the startup process messages. Supplementary: This article and subsequent releases are based on the Spring-5.1.14 release

Spring using the Demo

public class DemoApplicationTest {

	public static void main(String[] args) {
		// Create a container
		ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);
		// Get the UserService object
		UserService userService = applicationContext.getBean(UserService.class);
		// Execute the test methoduserService.test(); }}@Configuration
@Import(UserService.class)
class AppConfig {}/ / UserSerivce class
@Service
public class UserService {
	public String test(a) {
		return "test"; }}Copy the code

Spring startup process and method entry

// The entry method
AbstractApplicationContext#refresh()

// 1. Pre-processing before the refresh
prepareRefresh();
// 2. Obtain the BeanFactory
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
// 3. BeanFactory preprocessing work
prepareBeanFactory(beanFactory);
// 4. Post processing after BeanFactory is finished
postProcessBeanFactory(beanFactory);
/ / 5. BeanFactoryPostProcessors execution
invokeBeanFactoryPostProcessors(beanFactory);
// 6. Register the Bean postprocessor [Intercept Bean creation.]
registerBeanPostProcessors(beanFactory);
// 7. Initialize the MessageSource component (for internationalization, message binding, message parsing)
initMessageSource();
// 8. Initialize the event dispatcher
initApplicationEventMulticaster();
// 9. Leave it to self-container (subclass)
onRefresh();
// 10. Register applicationListeners for all projects in the container
registerListeners();
// 11. Initialize all non-lazily loaded singleton beans
finishBeanFactoryInitialization(beanFactory);
// 12. Execute the Spring container lifecycle (start) and publish events
finishRefresh();
Copy the code

Describes the Spring startup process

1. PrepareRefresh () preprocessing before the refresh

  • Recording startup events
  • Allows subcontainers to set some properties to the environment
  • Check whether the derived attribute is valid and contains the required attribute
  • The implementation code is as follows:
protected void prepareRefresh(a) {
    // Switch to active.
    this.startupDate = System.currentTimeMillis();
    // Whether the container is closed
    this.closed.set(false);
    // Start the container
    this.active.set(true);

    if (logger.isDebugEnabled()) {
        if (logger.isTraceEnabled()) {
            logger.trace("Refreshing " + this);
        }
        else {
            logger.debug("Refreshing "+ getDisplayName()); }}// Initialize any placeholder property sources in the context environment.
    // 1. Initialize some property Settings to allow the child container to set some content to the environment
    initPropertySources();

    // Validate that all properties marked as required are resolvable:
    // see ConfigurablePropertyResolver#setRequiredProperties
    // 2. Verify whether the mandatory attribute has a value
    getEnvironment().validateRequiredProperties();

    // Store pre-refresh ApplicationListeners...
    if (this.earlyApplicationListeners == null) {
        this.earlyApplicationListeners = new LinkedHashSet<>(this.applicationListeners);
    }
    else {
        // Reset local application listeners to pre-refresh state.
        this.applicationListeners.clear();
        this.applicationListeners.addAll(this.earlyApplicationListeners);
    }

    // Allow for the collection of early ApplicationEvents,
    // to be published once the multicaster is available...
    // 3. Create a collection to hold some early events of the container
    this.earlyApplicationEvents = new LinkedHashSet<>();
}
Copy the code
  • In Spring MVCinitPropertySourcesThe Servlet container-related information is put into the environment
/ / Spring MVC GenericWebApplicationContext classes
protected void initPropertySources(a) {
    ConfigurableEnvironment env = getEnvironment();
    if (env instanceof ConfigurableWebEnvironment) {
        ((ConfigurableWebEnvironment) env).initPropertySources(this.servletContext, null); }}Copy the code

2. ObtainFreshBeanFactory () gets the BeanFactory object

  • Refresh the BeanFactory
/ / create the BeanFactory is no arguments in AbstractApplicationContext initialized in the constructor
/ / GenericApplicationContext class
public GenericApplicationContext(a) {
    this.beanFactory = new DefaultListableBeanFactory();
}

/ / AnnotationConfigApplicationContext class definition of signatures and inheritance relationships
public class AnnotationConfigApplicationContext extends GenericApplicationContext implements AnnotationConfigRegistry {
	/ /...
}
Copy the code
  • callobtainFreshBeanFactoryMethod returns BeanFactory
protected ConfigurableListableBeanFactory obtainFreshBeanFactory(a) {
    // 1. Refresh [create] BeanFactory
    refreshBeanFactory();
    // 2. Return BeanFactory
    return getBeanFactory();
}
Copy the code
  • Note:refreshBeanFactoryMethods have two implementation classesAbstractRefreshableApplicationContext , GenericApplicationContextWe currently create the container that you useAnnotationConfigApplicationContextIt isGenericApplicationContextSo the current containerDoes not supportRefresh again. If you need to refresh again, you can chooseAnnotationConfigWebApplicationContextClass.
AnnotationConfigApplicationContext application =new AnnotationConfigApplicationContext();
application.register(ApplicationConfig.class);
application.refresh();
application.refresh(); // Error: IllegalStateException
Copy the code

3. PrepareBeanFactory

protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) { // 1. Set up BeanFactory's classloader to support the expression parser.... beanFactory.setBeanClassLoader(getClassLoader()); / / el parser. The beanFactory setBeanExpressionResolver (new StandardBeanExpressionResolver (the beanFactory. GetBeanClassLoader ())); / / default type converter the beanFactory addPropertyEditorRegistrar (new ResourceEditorRegistrar (this, getEnvironment ())); / / 2. Add a part of the BeanFactory BeanPostProcessor [ApplicationContextAwareProcessor] / / rear Bean processors beanFactory.addBeanPostProcessor(new ApplicationContextAwareProcessor(this)); / / 3 set to ignore automatic assembly interface EnvironmentAware, EmbeddedValueResolverAware / / if the implementation of these interfaces to rewrite set method, Then the Spring will not go to the assembly the beanFactory. IgnoreDependencyInterface (EnvironmentAware. Class); beanFactory.ignoreDependencyInterface(EmbeddedValueResolverAware.class); beanFactory.ignoreDependencyInterface(ResourceLoaderAware.class); beanFactory.ignoreDependencyInterface(ApplicationEventPublisherAware.class); beanFactory.ignoreDependencyInterface(MessageSourceAware.class); beanFactory.ignoreDependencyInterface(ApplicationContextAware.class); // 4. Register resolvable autoassembly, which we can automatically inject directly into any component: / / the BeanFactory, ResourceLoader, ApplicationEventPublisher, ApplicationContext beanFactory.registerResolvableDependency(BeanFactory.class, beanFactory); beanFactory.registerResolvableDependency(ResourceLoader.class, this); beanFactory.registerResolvableDependency(ApplicationEventPublisher.class, this); beanFactory.registerResolvableDependency(ApplicationContext.class, this); / / 5. Add the BeanPostProcessor. 【 ApplicationListenerDetector 】 the beanFactory addBeanPostProcessor (new ApplicationListenerDetector(this)); / / 6. Add the compile-time AspectJ support the if (the beanFactory. ContainsBean (LOAD_TIME_WEAVER_BEAN_NAME)) {the beanFactory. AddBeanPostProcessor (new  LoadTimeWeaverAwareProcessor(beanFactory)); // Set a temporary ClassLoader for type matching. beanFactory.setTempClassLoader(new ContextTypeMatchClassLoader(beanFactory.getBeanClassLoader())); } // 7. Register some components that can be used in BeanFactory: // systemProperties [Map<String, Object>] // systemEnvironment [Map<String, Object>] Object > 】 the if (! beanFactory.containsLocalBean(ENVIRONMENT_BEAN_NAME)) { beanFactory.registerSingleton(ENVIRONMENT_BEAN_NAME, getEnvironment()); } if (! beanFactory.containsLocalBean(SYSTEM_PROPERTIES_BEAN_NAME)) { beanFactory.registerSingleton(SYSTEM_PROPERTIES_BEAN_NAME,  getEnvironment().getSystemProperties()); } if (! beanFactory.containsLocalBean(SYSTEM_ENVIRONMENT_BEAN_NAME)) { beanFactory.registerSingleton(SYSTEM_ENVIRONMENT_BEAN_NAME, getEnvironment().getSystemEnvironment()); }}Copy the code

4. postProcessBeanFactory(beanFactory)

  • This method is used to extend the subclass

5. InvokeBeanFactoryPostProcessors (the beanFactory) perform the beanFactory post processor

1. Get all the BeanDefinitionRegistryPostProcessor 2. To perform first realized PriorityOrdered BeanDefinitionRegistryPostProcessor 3 priority interface. Perform implements BeanDefinitionRegistryPostProcessor 4 Ordered sequence interface. The final step execution does not implement the interfaces or the order of priority BeanDefinitionRegistryPostProcessors 5. Get all BeanFactoryPostProcessor 6. Execute BeanFactoryPostProcessor 7 that implements the PriorityOrdered priority interface. Execute BeanFactoryPostProcessor 8 that implements the Ordered order interface. Executes a BeanFactoryPostProcessor that does not implement a priority interface or a sequential interfaceCopy the code
/ * * * * to perform BeanFactoryPostProcessors method@param beanFactory
 * @param beanFactoryPostProcessors
 */
public static void invokeBeanFactoryPostProcessors( ConfigurableListableBeanFactory beanFactory, List
       
         beanFactoryPostProcessors)
        {

	// Invoke BeanDefinitionRegistryPostProcessors first, if any.
	Set<String> processedBeans = new HashSet<>();

	if (beanFactory instanceof BeanDefinitionRegistry) {
		BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
		List<BeanFactoryPostProcessor> regularPostProcessors = new ArrayList<>();
		List<BeanDefinitionRegistryPostProcessor> registryProcessors = new ArrayList<>();

		for (BeanFactoryPostProcessor postProcessor : beanFactoryPostProcessors) {
			if (postProcessor instanceof BeanDefinitionRegistryPostProcessor) {
				BeanDefinitionRegistryPostProcessor registryProcessor =
						(BeanDefinitionRegistryPostProcessor) postProcessor;
				registryProcessor.postProcessBeanDefinitionRegistry(registry);
				registryProcessors.add(registryProcessor);
			}
			else{ regularPostProcessors.add(postProcessor); }}// Do not initialize FactoryBeans here: We need to leave all regular beans
		// uninitialized to let the bean factory post-processors apply to them!
		// Separate between BeanDefinitionRegistryPostProcessors that implement
		// PriorityOrdered, Ordered, and the rest.
		List<BeanDefinitionRegistryPostProcessor> currentRegistryProcessors = new ArrayList<>();


		/ / 1. Get all the BeanDefinitionRegistryPostProcessor
		String[] postProcessorNames =
				beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true.false);
                
		/ / 2. To perform first realized PriorityOrdered interface BeanDefinitionRegistryPostProcessor priority,
		// postProcessor.postProcessBeanDefinitionRegistry(registry);
		for (String ppName : postProcessorNames) {
			if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
				currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
				processedBeans.add(ppName);
			}
		}
		sortPostProcessors(currentRegistryProcessors, beanFactory);
		registryProcessors.addAll(currentRegistryProcessors);
		invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry);
		currentRegistryProcessors.clear();

		/ / 3. Perform implements BeanDefinitionRegistryPostProcessor Ordered sequence interface
		postProcessorNames = beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true.false);
		for (String ppName : postProcessorNames) {
			if(! processedBeans.contains(ppName) && beanFactory.isTypeMatch(ppName, Ordered.class)) { currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class)); processedBeans.add(ppName); } } sortPostProcessors(currentRegistryProcessors, beanFactory); registryProcessors.addAll(currentRegistryProcessors); invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry); currentRegistryProcessors.clear();/ / 4. The last step performed no implementation BeanDefinitionRegistryPostProcessors interfaces or the order of priority
		boolean reiterate = true;
		while (reiterate) {
			reiterate = false;
			postProcessorNames = beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true.false);
			for (String ppName : postProcessorNames) {
				if(! processedBeans.contains(ppName)) { currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class)); processedBeans.add(ppName); reiterate =true;
				}
			}
			sortPostProcessors(currentRegistryProcessors, beanFactory);
			registryProcessors.addAll(currentRegistryProcessors);
			invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry);
			currentRegistryProcessors.clear();
		}

		// Now, invoke the postProcessBeanFactory callback of all processors handled so far.
		invokeBeanFactoryPostProcessors(registryProcessors, beanFactory);
		invokeBeanFactoryPostProcessors(regularPostProcessors, beanFactory);
	}

	else {
		// Invoke factory processors registered with the context instance.
		invokeBeanFactoryPostProcessors(beanFactoryPostProcessors, beanFactory);
	}

	// Execute BeanFactoryPostProcess
	String[] postProcessorNames =
			beanFactory.getBeanNamesForType(BeanFactoryPostProcessor.class, true.false);

	// Separate between BeanFactoryPostProcessors that implement PriorityOrdered,
	// Ordered, and the rest.
	List<BeanFactoryPostProcessor> priorityOrderedPostProcessors = new ArrayList<>();
	List<String> orderedPostProcessorNames = new ArrayList<>();
	List<String> nonOrderedPostProcessorNames = new ArrayList<>();
	for (String ppName : postProcessorNames) {
		if (processedBeans.contains(ppName)) {
			// skip - already processed in first phase above
		}
		else if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
			priorityOrderedPostProcessors.add(beanFactory.getBean(ppName, BeanFactoryPostProcessor.class));
		}
		else if (beanFactory.isTypeMatch(ppName, Ordered.class)) {
			orderedPostProcessorNames.add(ppName);
		}
		else{ nonOrderedPostProcessorNames.add(ppName); }}// 2. Execute BeanFactoryPostProcessor, which implements the PriorityOrdered priority interface,
	// postProcessor.postProcessBeanFactory(beanFactory);
	sortPostProcessors(priorityOrderedPostProcessors, beanFactory);
	invokeBeanFactoryPostProcessors(priorityOrderedPostProcessors, beanFactory);

	// 3. Execute the BeanFactoryPostProcessor that implements the Ordered order interface
	List<BeanFactoryPostProcessor> orderedPostProcessors = new ArrayList<>();
	for (String postProcessorName : orderedPostProcessorNames) {
		orderedPostProcessors.add(beanFactory.getBean(postProcessorName, BeanFactoryPostProcessor.class));
	}
	sortPostProcessors(orderedPostProcessors, beanFactory);
	invokeBeanFactoryPostProcessors(orderedPostProcessors, beanFactory);

	// 4. The last step is to execute the BeanFactoryPostProcessor that does not implement the priority interface or the sequential interface
	List<BeanFactoryPostProcessor> nonOrderedPostProcessors = new ArrayList<>();
	for (String postProcessorName : nonOrderedPostProcessorNames) {
		nonOrderedPostProcessors.add(beanFactory.getBean(postProcessorName, BeanFactoryPostProcessor.class));
	}
	invokeBeanFactoryPostProcessors(nonOrderedPostProcessors, beanFactory);

	// Clear cached merged bean definitions since the post-processors might have
	// modified the original metadata, e.g. replacing placeholders in values...
	beanFactory.clearMetadataCache();
}
Copy the code

6. RegisterBeanPostProcessors rear (the beanFactory) registered Bean processors

  • BeanPostProcessor sorting, sorting is divided into three categories: PriorityOrdered, Ordered, non default, MergedBeanDefinitionPostProcessor
  • Sorted by deposit to priorityOrderedPostProcessors orderedPostProcessors, nonOrderedPostProcessors, internalPostProcessors collection
  • Here the priority is:PriorityOrdered - > Ordered - > no - > MergedBeanDefinitionPostProcessorNote:If multiple interfaces are implemented, the order is the lowest priority
  • Register the post-processor in sequence
  • The last registered a ApplicationListenerDetector into the container
public static void registerBeanPostProcessors( ConfigurableListableBeanFactory beanFactory, AbstractApplicationContext applicationContext) {
	// 1. Obtain all BeanPostProcessor; The rear processor can specify the priority through the PriorityOrdered, Ordered interface
	String[] postProcessorNames = beanFactory.getBeanNamesForType(BeanPostProcessor.class, true.false);

	// Register BeanPostProcessorChecker that logs an info message when
	// a bean is created during BeanPostProcessor instantiation, i.e. when
	// a bean is not eligible for getting processed by all BeanPostProcessors.
	int beanProcessorTargetCount = beanFactory.getBeanPostProcessorCount() + 1 + postProcessorNames.length;
	beanFactory.addBeanPostProcessor(new BeanPostProcessorChecker(beanFactory, beanProcessorTargetCount));

	// Separate between BeanPostProcessors that implement PriorityOrdered,
	// Ordered, and the rest.
	List<BeanPostProcessor> priorityOrderedPostProcessors = new ArrayList<>();
	List<BeanPostProcessor> internalPostProcessors = new ArrayList<>();
	List<String> orderedPostProcessorNames = new ArrayList<>();
	List<String> nonOrderedPostProcessorNames = new ArrayList<>();
	for (String ppName : postProcessorNames) {
		if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {// PriorityOrdered @Order @Priority
			BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
			priorityOrderedPostProcessors.add(pp);
			if (pp instanceofMergedBeanDefinitionPostProcessor) { internalPostProcessors.add(pp); }}else if (beanFactory.isTypeMatch(ppName, Ordered.class)) {
			orderedPostProcessorNames.add(ppName);
		}
		else{ nonOrderedPostProcessorNames.add(ppName); }}// 2. Register BeanPostProcessors for the PriorityOrdered priority interface
	sortPostProcessors(priorityOrderedPostProcessors, beanFactory);
	registerBeanPostProcessors(beanFactory, priorityOrderedPostProcessors);

	// 3. Register BeanPostProcessors for the Order priority interface
	List<BeanPostProcessor> orderedPostProcessors = new ArrayList<>();
	for (String ppName : orderedPostProcessorNames) {
		BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
		orderedPostProcessors.add(pp);
		if (pp instanceof MergedBeanDefinitionPostProcessor) {
			internalPostProcessors.add(pp);
		}
	}
	sortPostProcessors(orderedPostProcessors, beanFactory);
	registerBeanPostProcessors(beanFactory, orderedPostProcessors);

	// 4. Register BeanPostProcessors without any priority interfaces
	List<BeanPostProcessor> nonOrderedPostProcessors = new ArrayList<>();
	for (String ppName : nonOrderedPostProcessorNames) {
		BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
		nonOrderedPostProcessors.add(pp);
		if (pp instanceof MergedBeanDefinitionPostProcessor) {
			internalPostProcessors.add(pp);
		}
	}
	registerBeanPostProcessors(beanFactory, nonOrderedPostProcessors);

	/ / 5. Registered MergedBeanDefinitionPostProcessor finally
	sortPostProcessors(internalPostProcessors, beanFactory);
	registerBeanPostProcessors(beanFactory, internalPostProcessors);

	// Re-register post-processor for detecting inner beans as ApplicationListeners,
	// moving it to the end of the processor chain (for picking up proxies etc).
	/ / 6. Register a ApplicationListenerDetector to create after the completion of the inspection on the Bean is ApplicationListener if it is
	beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(applicationContext));
}
Copy the code

7. InitMessageSource () Initializes the MessageSource component

8. InitApplicationEventMulticaster distributed () to initialize the event

protected void initApplicationEventMulticaster(a) {
	// 1. Obtain the BeanFactory
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	/ / 2. From the BeanFactory applicationEventMulticaster applicationEventMulticaster
	if (beanFactory.containsLocalBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) {
		this.applicationEventMulticaster =
				beanFactory.getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class);
		if (logger.isTraceEnabled()) {
			logger.trace("Using ApplicationEventMulticaster [" + this.applicationEventMulticaster + "]"); }}else {
		/ / 3. If the previous step no configuration: create a SimpleApplicationEventMulticaster
		this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory);
		/ / 4. Will create ApplicationEventMulticaster added to the BeanFactory, after other components direct injection can automatically
		beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster);
		if (logger.isTraceEnabled()) {
			logger.trace("No '" + APPLICATION_EVENT_MULTICASTER_BEAN_NAME + "' bean, using " +
					"[" + this.applicationEventMulticaster.getClass().getSimpleName() + "]"); }}}Copy the code

9. OnRefresh () reserves the method for custom implementations to override the handling of the implementation of a particular Bean

10. RegisterListeners (

protected void registerListeners(a) {
	// Register statically specified listeners first.
	// 1. Get all ApplicationListener components from the container
	for(ApplicationListener<? > listener : getApplicationListeners()) { getApplicationEventMulticaster().addApplicationListener(listener); }// Do not initialize FactoryBeans here: We need to leave all regular beans
	// uninitialized to let post-processors apply to them!
	// 2. Each listener is added to the event dispatcher
	// getApplicationEventMulticaster().addApplicationListenerBean(listenerBeanName);
	FactoryBean hasn't called the getObject() method to generate the Bean object yet, so it's time to look for the corresponding type of the ApplicationListener record by type
	String[] listenerBeanNames = getBeanNamesForType(ApplicationListener.class, true.false);
	for (String listenerBeanName : listenerBeanNames) {
		getApplicationEventMulticaster().addApplicationListenerBean(listenerBeanName);
	}

	// Publish early application events now that we finally have a multicaster...
	// 3. Dispatch events generated by previous steps
	Set<ApplicationEvent> earlyEventsToProcess = this.earlyApplicationEvents;
	this.earlyApplicationEvents = null;
	if(earlyEventsToProcess ! =null) {
		for(ApplicationEvent earlyEvent : earlyEventsToProcess) { getApplicationEventMulticaster().multicastEvent(earlyEvent); }}}Copy the code

11. FinishBeanFactoryInitialization (the beanFactory) to refresh the pretreatment before work

1. Initialize the singleton Bean. 2. Assign attributes and parts will extend in Bean initialization, dependency injection, and cyclic dependencyCopy the code

12. FinishRefresh () performs the life cycle start and time release of the Bean

protected void finishRefresh(a) {
	// Clear context-level resource caches (such as ASM metadata from scanning).
	clearResourceCaches();

	// Initialize lifecycle processor for this context.
	// 2. initLifecycleProcessor(); Initialize the post-processor with respect to its life cycle
	// By default, look for a component from the container for lifecycleProcessor. If not, use the default lifecycle component
	// new DefaultLifecycleProcessor();
	// Add to the container for easy use
	// LifecycleProcessor writes an implementation class for LifecycleProcessor that can be called in BeanFactory methods
	// void onRefresh();
	// void onClose();
	initLifecycleProcessor();

	// Propagate refresh to lifecycle processor first.
	// 3. Get the life cycle processor (BeanFactory) callback onRefresh(),
	getLifecycleProcessor().onRefresh();

	// Publish the final event.
	// 4. publishEvent(new ContextRefreshedEvent(this)); Publish the container refresh completion event
	publishEvent(new ContextRefreshedEvent(this));

	// Participate in LiveBeansView MBean, if active.
	// 5. LiveBeansView.registerApplicationContext(this);
	LiveBeansView.registerApplicationContext(this);
}
Copy the code

Spring source parsing

  • Spring Startup Process
  • The life cycle of Spring Beans
  • Spring Attribute Injection
  • Spring loop dependencies
  • Spring Aop
  • Spring transactions
  • Spring integration MyBatis
  • Spring FAQ