Spring Boot 實例化bean如何選擇代理方式
Spring Boot 實例化bean如何選擇代理方式
圖1
我們再回顧一下之前的事務(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動態(tài)代理;
以上就是Spring Boot 實例化bean如何選擇代理方式的詳細(xì)內(nèi)容,更多關(guān)于SpringBoot實例化bean代理的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
springboot整合gateway實現(xiàn)網(wǎng)關(guān)功能的示例代碼
本文主要介紹了springboot整合gateway實現(xiàn)網(wǎng)關(guān)功能的示例代碼,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02JWT在OpenFeign調(diào)用中進(jìn)行令牌中繼詳解
Feign是一個聲明式的Web Service客戶端,是一種聲明式、模板化的HTTP客戶端。而OpenFeign是Spring Cloud 在Feign的基礎(chǔ)上支持了Spring MVC的注解,如@RequesMapping等等,這篇文章主要給大家介紹了關(guān)于JWT在OpenFeign調(diào)用中進(jìn)行令牌中繼的相關(guān)資料,需要的朋友可以參考下2021-10-10