Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

step9循环依赖的问题 #17

Open
archer4117 opened this issue Aug 16, 2018 · 1 comment
Open

step9循环依赖的问题 #17

archer4117 opened this issue Aug 16, 2018 · 1 comment

Comments

@archer4117
Copy link

AbstractBeanFactory类中:
@OverRide
public Object getBean(String name) throws Exception {
BeanDefinition beanDefinition = beanDefinitionMap.get(name);
if (beanDefinition == null) {
throw new IllegalArgumentException("No bean named " + name + " is defined");
}
Object bean = beanDefinition.getBean();
if (bean == null) {
bean = doCreateBean(beanDefinition);
bean = initializeBean(bean, name);
beanDefinition.setBean(bean);
}
return bean;
}

beanDefinition.setBean(bean);上面这行代码在原代码中没有这一行导致生成的对象非代理对象,aop不生效。但是加上之后循环引用有个问题。
A B两个类相互引用
假如AB 按顺序加载 那么调用的方法步骤为
A ->doCreateBean(beanDefinition);
B ->doCreateBean(beanDefinition);
B.setA(A) //此A为提前暴露在beanDefinitionMap中的A
B ->initializeBean(bean, name);
A.setB(B); //此时B为jdk生成的动态代理对象。
A ->initializeBean(bean, name);

以上步骤执行完成之后,A中的B是代理对象,但是B中的A还是提前暴露的对象,并没有更新成代理对象。这样的话引用就不一致了。不知道有什么办法可以解决这个问题吗。

@xdkxlk
Copy link

xdkxlk commented Jan 9, 2019

请问有什么好的解决办法了么

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants