三行代碼引發對SpringAop代理過程的認知

@EnableAspectJAutoProxy(proxyTargetClass = true)<!--Cglib代理,其中TaskManageServiceImpl類已去掉接口實現-->
第一行:AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(BizInsertFromSqlAndExcel.class);
第二行:TaskManageServiceImpl taskManageService = (TaskManageServiceImpl) annotationConfigApplicationContext.getBean(name:"taskManageService");
第三行:taskManageService.executeTask(0, 1);

@EnableAspectJAutoProxy(proxyTargetClass = false)<!--默認false,即Jdk動態代理,接口-->
第一行:AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(BizInsertFromSqlAndExcel.class);
第二行:ITaskManageService taskManageService = annotationConfigApplicationContext.getBean(ITaskManageService.class);
第三行:taskManageService.executeTask(0, 1);

歷經重重磨難,繁雜的Spring源碼Debug<條件斷點>過程之後,終於回來啦👉yxd179
梳理幾點Step Key:
-->org.springframework.context.support.AbstractApplicationContext.getBean(java.lang.String)
   -->org.springframework.context.support.AbstractApplicationContext.getBeanFactory()
         -->org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean()
           >org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton()👉

綜上Debug,相信小夥伴已get到上篇博文提到的默認代理終究花落誰家啦,那Jdk動態代理又爲什麼只能是接口?這個其實是跟java的單一繼承,多重實現有關訥,反射與字節碼下回go👉

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章