In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the knowledge points of Spring IOC". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the knowledge points of Spring IOC"?
The refresh () method of AbstractApplicationContext is the core of spring, where the container is initialized. Let's take a brief look at the declaration process of the business Bean:
The process of a business Bean is just an item about the creation of a business Bean in the refresh function, but the process is generally similar.
General process of IOC
The entry to the spring container refresh ()
PrepareRefresh (): pre-processing before refresh
InitPropertySources (): initializes some property settings; the subclass customizes the personalized property setting method
GetEnvironment (). ValidateRequiredProperties (): verify the validity of attributes, etc.
This.earlyApplicationEvents = new LinkedHashSet (); save some early events in the container
ObtainFreshBeanFactory ()
Get beanFactory instance
RefreshBeanFactory (); refresh or create beanFactory
GetBeanFactory (): returns the newly generated beanFactory
PrepareBeanFactory (beanFactory):
BeanFactory preparation work, (many of the beanFactory properties created above have no values, only some default values)
BeanFactory.setBeanClassLoader (getClassLoader ()); sets the classloader for BeanFactory
BeanFactory.setBeanExpressionResolver: supports parsing of related expression languages
IgnoreDependencyInterface: sets the ignored auto-assembly interface EnvironmentAware EmbeddedValueResolverAware
BeanFactory.registerResolvableDependency: register parsable autoassembly: we can automatically inject BeanFactory ApplicationContext directly into any component
BeanFactory.addBeanPostProcessor (new ApplicationListenerDetector (this)); add processor for snooping detection
If (! beanFactory.containsLocalBean (ENVIRONMENT_BEAN_NAME)): register the bean associated with the environment variable
PostProcessBeanFactory (beanFactory)
Subclasses implement their own business logic by overriding this method.
PS: create and prepare the BeanFactory through the above preparation
5. InvokeBeanFactoryPostProcessors (beanFactory)
The post processor that executes the BeanFactoryPostProcessor. It was delayed between 2 and 3. There are two interfaces that need to implement BeanFactoryPostProcessor and BeanDefinitionRegistryPostProcessor.
RegisterBeanPostProcessors (beanFactory)
BeanPostProcessor's bean is extended in instantiating and registering beanFactory. The function is to intercept our business Bean creation and enhance it by annotating dynamic agents. Please refer to the AOP process.
InitMessageSource ()
Label internationalization resource, initialize MessageSource (internationalization function: message parsing, message binding)
InitApplicationEventMulticaster ()
Initialize event dispatcher
OnRefresh ()
A method that is left for subclasses to override, and the logic can be customized when the container is refreshed.
RegisterListeners ()
Register the ApplicationListener of all projects in the container.
FinishBeanFactoryInitialization (beanFactory)
Initialize the loading of the single instance Bean that is not lazily loaded in the project, which is also followed by the AOP process.
FinishRefresh ()
Other things that refresh needs to do after it is done. Clear the context resource cache (such as ASM metadata in a scan)
Initialize the lifecycle processor of the context and refresh it (find the bean in the Spring container that implements the Lifecycle interface and execute the start () method). Issue a ContextRefreshedEvent event to tell the corresponding ApplicationListener to respond
General process: do some preprocessing work under refresh, instantiate BeanFactory, assign several parameters of BeanFactory, post-processor of BeanFactory, register operation of some annotated Bean, internationalization, event release mechanism, monitoring mechanism, creation of business Bean. It involves singleton patterns, engineering patterns, adapter patterns, dynamic proxies, and so on.
IOC core flow chart
If the picture is too large to be seen clearly, the official account [SoWhat1412] can reply to AOP to get a high-definition picture.
At this point, I believe you have a deeper understanding of "what knowledge points Spring IOC has". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.