Spring Boot 实例化bean如何选择代理方式
Spring Boot 实例化bean如何选择代理方式

图1
我们再回顾一下之前的事务源码分析有提到
执行到AbstractAutowireCapableBeanFactory.initializeBean()->applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName)->AbstractAutoProxyCreator.postProcessAfterInitialization()->AbstractAutoProxyCreator.wrapIfNecessary()->DefaultAopProxyFactory.createAopProxy()
链条创建代理
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动态代理;
以上就是Spring Boot 实例化bean如何选择代理方式的详细内容,更多关于SpringBoot实例化bean代理的资料请关注脚本之家其它相关文章!
相关文章
springboot整合gateway实现网关功能的示例代码
本文主要介绍了springboot整合gateway实现网关功能的示例代码,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2022-02-02


最新评论