Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use prepareRefresh ()

Shulou Source: shulou.com Published: 2022-06-03 06:31:02 11月16日 Update

This article mainly introduces "how to use prepareRefresh ()". In daily operation, I believe many people have doubts about how to use prepareRefresh (). The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use prepareRefresh ()"! Next, please follow the editor to study!

Refresh ()

This method mainly does the following things:

Preparation before container refresh

Initialize beanFactory, load and parse the configuration

Set the properties of beanFactory

Post-processing work after the creation of BeanFactory

The method of executing BeanFactoryPostProcessor

Register for BeanPostProcessor

Initialize the MessageSource component

Initialize event dispatcher

Subclass overrides this method to customize the logic when the container is refreshed

Register the ApplicationListener in all projects in the container

Initialize all remaining single instance bean

After the initialization and creation of BeanFactory, the IOC container is created.

Here, let's take a look at what the container did before it was refreshed.

PrepareRefresh ()

There is not much source code for the method, as follows:

Protected void prepareRefresh () {/ / Switch to active. / / this sentence obviously gets the current time of the system. In fact, its function is to record the this.startupDate = System.currentTimeMillis () of the current startup time; / / the settings of these two states, the former closes the program to be set to false, and the latter's running flag is set to true this.closed.set (false); 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. / / currently it is an empty method, so initPropertySources () should be added later; / / Validate that all properties marked as required are resolvable: / / see ConfigurablePropertyResolver#setRequiredProperties / / verify the xml configuration file getEnvironment () .validateRequiredProperties (); / / Store pre-refresh ApplicationListeners... / / determine whether the collection of application listeners before refresh is empty, initialize applicationListeners listeners, and not empty, then empty the listener 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... / / create the event collection before refresh this.earlyApplicationEvents = new LinkedHashSet ();}

This method prepareRefresh () is added after spring5.3, so there is no way to see the previous version.

That's all I've done.

Set the startup time of the container

Set active status to true

Set the shutdown status to false

Get the Environment object and load the current system environment into Environment

Prepare the collection object for listeners and events. Default is empty.

At this point, the study on "how to use prepareRefresh ()" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Methods containers learning listening events times states programs things objects more listeners systems preparation work help configuration practical obvious next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft Xiaomi NVidia Linux