Spring Boot 實(shí)例化bean如何選擇代理方式
Spring Boot 實(shí)例化bean如何選擇代理方式
圖1
我們?cè)倩仡櫼幌轮暗氖聞?wù)源碼分析有提到
執(zhí)行到AbstractAutowireCapableBeanFactory.initializeBean()->applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName)->AbstractAutoProxyCreator.postProcessAfterInitialization()->AbstractAutoProxyCreator.wrapIfNecessary()->DefaultAopProxyFactory.createAopProxy()
鏈條創(chuàng)建代理
public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException { if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) { Class<?> targetClass = config.getTargetClass(); if (targetClass == null) { throw new AopConfigException("TargetSource cannot determine target class: " + "Either an interface or a target is required for proxy creation."); } //如果是接口 if (targetClass.isInterface() || Proxy.isProxyClass(targetClass)) { return new JdkDynamicAopProxy(config); } //如果不是接口 return new ObjenesisCglibAopProxy(config); } else { return new JdkDynamicAopProxy(config); } }
通過上面的方式判斷cglib還是jdk動(dòng)態(tài)代理;
以上就是Spring Boot 實(shí)例化bean如何選擇代理方式的詳細(xì)內(nèi)容,更多關(guān)于SpringBoot實(shí)例化bean代理的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
springboot整合gateway實(shí)現(xiàn)網(wǎng)關(guān)功能的示例代碼
本文主要介紹了springboot整合gateway實(shí)現(xiàn)網(wǎng)關(guān)功能的示例代碼,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02JWT在OpenFeign調(diào)用中進(jìn)行令牌中繼詳解
Feign是一個(gè)聲明式的Web Service客戶端,是一種聲明式、模板化的HTTP客戶端。而OpenFeign是Spring Cloud 在Feign的基礎(chǔ)上支持了Spring MVC的注解,如@RequesMapping等等,這篇文章主要給大家介紹了關(guān)于JWT在OpenFeign調(diào)用中進(jìn)行令牌中繼的相關(guān)資料,需要的朋友可以參考下2021-10-10Java多線程文件分片下載實(shí)現(xiàn)的示例代碼
這篇文章主要介紹了Java多線程文件分片下載實(shí)現(xiàn)的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03