In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to initialize containers and DefaultListableBeanFactory". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1 entrance
The AnnotationConfigApplicationContext startup for loading a configuration from JavaConfig is as follows:
When you go in, you find that the construct is actually the current no-parameter construct of the call.
Therefore, no-parameter construction can also be declared directly at startup, which can be rewritten as follows:
Public class AnnotationConfigApplicationTest {public static void main (String [] args) {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext (); context.register (JavaConfig.class); context.refresh (); System.out.println (context.getBean (UserComponent.class));}}
Today, we will study what kind of logic has been done in this part of the non-parametric structure!
Non-parametric structure
StartupStep is a new class in 5.3. the code comments mean that it is used to record some metric information during the startup process. No research for the time being.
Mainly study the red frame part! Note that this piece does not mean that there is only the red box!
Because AnnotationConfigApplicationContext inherits GenericApplicationContext, the constructor of the parent class is executed first.
So a container for DefaultListableBeanFactory will be created here.
DefaultListableBeanFactory
DefaultListableBeanFactory UML
Although Spring's BeanFactory defines the basic concepts and interface methods of containers, DefaultListableBeanFactory is a concrete container that can really be new, and it can also be called a bean factory for the time being.
Let's take a look at what's in the DefaultListableBeanFactory.
Many parameters are initialized in DefaultListableBeanFactory, with the focus on the following two parameters:
/ * Map of bean definition objects, keyed by bean name. * / / BeanDefinition storage Map where key is beanName private final Map beanDefinitionMap = new ConcurrentHashMap; / * List of bean definition names, in registration order. * / / the collection of BeanName private volatile List beanDefinitionNames = new ArrayList
BeanDefinition describes a bean instance with attribute values, constructor parameter values, and more information provided by the implementation.
The corresponding beanDefinitionMap is the initialized beanName and BeanDefinition of the storage.
As for the specific content of BeanDefinition, we will introduce it in the next section.
two。 Summary
Through the above reading, you can add some modules to the initialization process, that is, instantiate DefaultListableBeanFactory
Review the concept of DefaultListableBeanFactory again.
Default implementation of ConfigurableListableBeanFactory and BeanDefinitionRegistry interfaces: a mature bean factory that defines metadata based on bean, which can be extended through post-processors. The key thing to grasp is that the Map of BeanDefinition is defined internally by DefaultListableBeanFactory.
This is the end of how to initialize containers and DefaultListableBeanFactory. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.