In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "brief introduction of Bean dependency injection". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the brief introduction of Bean dependency injection".
The container calls bd.getPropertyValues (). AddPropertyValue (pv) when loading BeanDefinition; the definition information of member variables is added to the BeanDefinition object
The container calls the populate () method in the doCreateBean () method of AbstractAutowireCapableBeanFactory to execute the logic of dependency injection.
When the populate () method is executed, mbd.getPropertyValues () is called to get the definition information of the member variables in the BeanDefinition object, based on which dependency injection is performed.
Protected void populateBean (String beanName, RootBeanDefinition mbd, @ Nullable BeanWrapper bw) {if (bw = = null) {.}. / / get the member variable definition information in the bean definition information PropertyValues pvs = (mbd.hasPropertyValues ()? Mbd.getPropertyValues (): null); if (mbd.getResolvedAutowireMode () = = RootBeanDefinition.AUTOWIRE_BY_NAME | | mbd.getResolvedAutowireMode () = = RootBeanDefinition.AUTOWIRE_BY_TYPE) {MutablePropertyValues newPvs = new MutablePropertyValues (pvs); / / Add property values based on autowire by name if applicable. If (mbd.getResolvedAutowireMode () = = RootBeanDefinition.AUTOWIRE_BY_NAME) {autowireByName (beanName, mbd, bw, newPvs);} / / Add property values based on autowire by type if applicable. If (mbd.getResolvedAutowireMode () = = RootBeanDefinition.AUTOWIRE_BY_TYPE) {autowireByType (beanName, mbd, bw, newPvs);} pvs = newPvs;}. If (pvs! = null) {/ / Application member variable definition information applyPropertyValues (beanName, mbd, bw, pvs);}}
ApplyPropertyValues (beanName, mbd, bw, pvs);-bw.setPropertyValues ()-setPropertyValue ()
Traverse the member variable definition information and inject it one by one
The container uses getBean () to get the bean according to the variable definition information, and then uses reflection to call the setterXxx () method or other methods to inject bean into the bean
Thank you for your reading, the above is the "brief introduction of Bean dependency injection" content, after the study of this article, I believe you have a deeper understanding of the simple introduction of Bean dependency injection, the specific use also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.