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/01 Report--
This article shows you how to parse the default tag source code in spring, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Default tag parsing try {String parent = null; if (ele.hasAttribute (PARENT_ATTRIBUTE)) {/ / determine whether there is a parent tag parent = ele.getAttribute (PARENT_ATTRIBUTE);} AbstractBeanDefinition bd = createBeanDefinition (className, parent) ParseBeanDefinitionAttributes (ele, beanName, containingBean, bd); bd.setDescription (DomUtils.getChildElementValueByTagName (ele, DESCRIPTION_ELEMENT)); parseMetaElements (ele, bd); parseLookupOverrideSubElements (ele, bd.getMethodOverrides ()); parseReplacedMethodSubElements (ele, bd.getMethodOverrides ()) ParseConstructorArgElements (ele, bd); parsePropertyElements (ele, bd); parseQualifierElements (ele, bd); bd.setResource (this.readerContext.getResource ()); bd.setSource (extractSource (ele)); return bd;} parent tag
Some parent class. This class uses the properties of parent
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext ("applicationContext.xml"); Child parent = applicationContext.getBean (Child.class); System.out.println ("name=" + parent.getName ()); System.out.println ("age=" + parent.getAge ()) Print result: name=ouyangfengage=18createBeanDefinition method: create GenericBeanDefinition instance parseBeanDefinitionAttributes method: parse the following properties singleton attribute / / Singleton pattern instantiate scope attribute / / scope request// scope session// scope globalsession// re-instantiate a new object abstract property / / define abstract class spring container does not create an object for this class every request. Lazy-init property / / delay loading, do not load when starting, load autowire property when getBean: auto-assemble No: do not start auto-assembly default byName: find and inject javaBean-dependent objects in spring IOC by the name of the attribute ByType: find javaBean dependent objects in spring IOC by type of attribute and inject default into them: constructor is determined by the default-autowire attribute of the parent tag: the same difference as buType is that instead of using the Seter method injection, the dependsOn attribute is injected through the constructor: the dependency of bean, which is first instantiated when the dependent bean starts, and destroys the beanOne dependent manager and accountDaoautowire-candidate attributes when closed: whether to automatically inject public class MessagePrinter {private MessageService service Public void setService (MessageService service) {this.service = service }} MessageServiceDBImpl and MessageServiceFileImpl are both implementation classes of MessageService. Only the primary attribute of the MessageServiceFileImpl class is automatically injected when instantiating MessagePrinter: preferably, when the container class has multiple bean of the same type, change the class to the preferred init-method attribute: execute the specified method destroy-method attribute when initializing the class: execute the specified method factory-method property when destroyed: call the factory class method ApplicationContext.getBean ("bmwCar") / / call the getCar method factory-bean attribute in the CarStaticFactory class when getting bean: instantiate the factory class parseMetaElements method to parse the meta element mete element using BeanDefinition bd;String beanCategoriesExpression = (String) bd.getAttribute (CATEGORY_META_KEY); parseLookupOverrideSubElements method: parse the lookup-method tag public abstract class GetBeanCase {public void showMe () {this.getBean (). ShowMe ();} public abstract User getBean () Public class Teacher extends User {public void showMe () {System.out.println ("i is Teacher");} public class Person extends User {public void showMe () {System.out.println ("i is Person");} ApplicationContext context = new ClassPathXmlApplicationContext ("appContext.xml"); GetBeanCase getBeanCase = (GetBeanCase) context.getBean ("getBeanCase"); getBeanCase.showMe () Print i is PersonparseReplacedMethodSubElements method: parse replaced-method tag ublic class MyBean {public void disPlay () {System.out.println ("me is original method");} public class MyBeanReplacer implements MethodReplacer {public Object reimplement (Object obj, Method method, Object [] args) throws Throwable {System.out.println ("I replaced the original method!"); return null;} ApplicationContext context = new ClassPathXmlApplicationContext ("replaceMethod.xml"); MyBean myBean = (MyBean) context.getBean ("myBean") MyBean.disPlay (); print I replaced the original method! The above content is how to parse the default tag source code in spring. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.