MethodOverrides Method coverage source analysis

as follows xml to configure :

<bean id="getBeanTest" class="springSourseAnalyes.GetBeanTest"
lazy-init="true"> <lookup-method name="getBean" bean="stu" /> </bean> <bean
id="stu" class="springSourseAnalyes.Student" lazy-init="true"/> <bean
id="teacher" class="springSourseAnalyes.Teacher" /> <bean id="testChangeMethod"
class="springSourseAnalyes.TestChangeMethod"> <replaced-method name="chanageMe"
replacer="replacer" /> </bean> <bean id="replacer"
class="springSourseAnalyes.TestMethodReplcer"/>
abstract class GetBeanTest code :
package springSourseAnalyes; public abstract class GetBeanTest { public void
showMe(){ getBean().showMe(); } abstract User getBean(); }
User Class and Teacher Class code :
package springSourseAnalyes; public class User { void showMe(){
System.out.println("i am user"); } } package springSourseAnalyes; public class
Teacher extends User{ @Override void showMe() { // TODO Auto-generated method
stub System.out.println("i am Teacher"); } }

actually MethodOverrides The role of spring Exists in the configuration lookup-mehtod and rreplace-method Of , And these two configurations are loading xml They will be stored in the BeanDefinition Medium methodOverrides Attribute .

View source code AbstractAutowireCapableBeanFactory The creation of bean Methods create:

At this time GetBeanTest Class is already class class , Start calling override of preparation method , Continue to enter the method prepareMethosOverrides().

View source code AbstractBeanDefinition

ergodic MethodOverrides, For the matching of a method j speak , If one l There are several overloaded methods in the class , that , In function call and enhancement, we also need to match according to the parameter type , To confirm which function is currently invoked. , however ,spring Part of the matching work is completed here , If there is only one method in the current class , The method is not overloaded , In this way, the method found can be used directly in subsequent calls , You don't need to j The parameters of the method are matched , Moreover, the existence of the method can be verified in advance .

Enter help class ClassUtils

The method of traversing the current class recursively , Whether or not methodName matching , If it matches, then count Counter auto increment , Then the interface of the current class is traversed and matched , Then, the super class of the current class is traversed and matched . Return counter .

Recursive traversal :1, Traversing the current method .2, Method traversal of current class interface .3, Method traversal of superclass of current class .

The final return is a proxy class for the current class . adopt CGLIB Generate different proxy classes .

among owner yes BeanFactory Interface ,beanDefinition by RootBeanDefinition class

When a method is called , Will be intercepted intercept method , Gets a replacement for the method bean class , And then through the owner.getBean To get bean class , Then the replaced method is actually called .

 

 

 

 

 

 

 

 

 

 

Technology
©2020 ioDraw All rights reserved
Huawei Hongmeng system learning notes 9- Ecological construction of developers JavaScript Do a simple guess number games Centralized processing (mean centering) The myth and truth of JS Experimental summary of basic key knowledge ( whole ) Detailed explanation PHP Medium die,exit,returnPython Student information management system ( Lite )re Common methods of modules stata Basic operation of linear regression analysis flutter study -- Search box Docker Import of containers and mirrors , export