提交 a9925f1b 编写于 作者: 希川's avatar 希川

<feat>: 循环依赖问题 - 改用jdk代理,如要使用cglib代理的话,得解决“代理的代理”的问题

上级 0b2c279b
package cn.noexception.container.aop;
import cn.noexception.container.factory.utils.ClassUtils;
/**
* TargetSource
*
......@@ -10,15 +12,18 @@ public class TargetSource {
private final Object target;
public TargetSource(Object target){
public TargetSource(Object target) {
this.target = target;
}
public Class<?>[] getTargetClass(){
return this.target.getClass().getInterfaces();
public Class<?>[] getTargetClass() {
Class<?> clazz = this.target.getClass();
// 如果是 cglib 代理的话,得获取 superClass 才可以
clazz = ClassUtils.isCglibProxyClass(clazz) ? clazz.getSuperclass() : clazz;
return clazz.getInterfaces();
}
public Object getTarget(){
public Object getTarget() {
return this.target;
}
......
......@@ -35,7 +35,7 @@ public class Cglib2AopProxy implements AopProxy {
private final AdvisedSupport advised;
private DynamicAdvisedInterceptor(AdvisedSupport advised) {
public DynamicAdvisedInterceptor(AdvisedSupport advised) {
this.advised = advised;
}
......
......@@ -22,8 +22,7 @@ public class BeanDefinition {
private boolean prototype = false;
public BeanDefinition(Class beanClass) {
this.beanClass = beanClass;
this.propertyValues = new PropertyValues();
this(beanClass, null);
}
public BeanDefinition(Class beanClass, PropertyValues propertyValues) {
......@@ -31,6 +30,21 @@ public class BeanDefinition {
this.propertyValues = propertyValues != null ? propertyValues : new PropertyValues();
}
public void setScope(String scope) {
this.scope = scope;
this.singleton = SCOPE_SINGLETON.equals(scope);
this.prototype = SCOPE_PROTOTYPE.equals(scope);
}
public boolean isSingleton() {
return singleton;
}
public boolean isPrototype() {
return prototype;
}
public Class getBeanClass() {
return beanClass;
}
......@@ -63,29 +77,4 @@ public class BeanDefinition {
this.destroyMethodName = destroyMethodName;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
this.singleton = SCOPE_SINGLETON.equals(scope);
this.prototype = SCOPE_PROTOTYPE.equals(scope);
}
public boolean isSingleton() {
return singleton;
}
public void setSingleton(boolean singleton) {
this.singleton = singleton;
}
public boolean isPrototype() {
return prototype;
}
public void setPrototype(boolean prototype) {
this.prototype = prototype;
}
}
......@@ -19,7 +19,9 @@ import java.lang.reflect.Method;
*/
public abstract class AbstractAutowiredCapableBeanFactory extends AbstractBeanFactory implements AutowireCapableBeanFactory {
private InstantiationStrategy instantiationStrategy = new CglibSubclassingInstantiationStrategy(); // 暂时默认选择 cglib 来实例化
// 实例化策略
// private InstantiationStrategy instantiationStrategy = new CglibSubclassingInstantiationStrategy(); // 选择使用 cglib代理来实例化
private InstantiationStrategy instantiationStrategy = new SimpleInstantiationStrategy(); // 选择使用 JDK代理 来实例化
protected Object doCreateBean(String beanName, BeanDefinition beanDefinition, Object[] args) {
Object bean = null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册