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

Fix stack overflow issue #6636

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,14 @@ private void findBusinessBeanNamesNeededEnhancement() {
try {
// get the class by bean definition class name
Class<?> beanClass = Class.forName(beanDefinition.getBeanClassName());

// 之前我想的是在 挪到这里 调用getRemotingFactoryBean(Object bean, String beanName),判断改bean是否是代理bean
// 后来发现这里,我是利用BeanDefinition,得到 bean 的类型Class<?>, 去判断该bean是否是 serviceBean. 所以根本用到 bean本身.
// 所以我觉得是否是可以直接去掉类RemotingFactoryBeanParser了?
// 而且getRemotingFactoryBean中有一个判断, 只有SpringProxyUtils.isProxy(bean) 才会区判断bean是否是remotingBean
// 进到SpringProxyUtils.isProxy()中,可以看到判断是的DubboUtil.isDubboProxyName(bean.getClass().getName()) || (Proxy.class.isAssignableFrom(bean.getClass()) || AopUtils.isAopProxy(bean))
// 在初始化没有完成的时候, 应该没有bean符合这个判断, 而且即使有符合这个判断,那么 这时候从 applicationContext取 bean也会促使bean提前初始化, 对后边逻辑会产生错误,笔记不会AOP自动代理处理.

// check if it needs enhancement by the class
IfNeedEnhanceBean ifNeedEnhanceBean = DefaultInterfaceParser.get().parseIfNeedEnhancement(beanClass);
if (!ifNeedEnhanceBean.isIfNeed()) {
Expand Down Expand Up @@ -547,8 +555,8 @@ private void findBusinessBeanNamesNeededEnhancement() {
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
RemotingFactoryBeanParser remotingFactoryBeanParser = new RemotingFactoryBeanParser(applicationContext);
DefaultRemotingParser.get().registerRemotingParser(remotingFactoryBeanParser);
// RemotingFactoryBeanParser remotingFactoryBeanParser = new RemotingFactoryBeanParser(applicationContext);
// DefaultRemotingParser.get().registerRemotingParser(remotingFactoryBeanParser);
this.setBeanFactory(applicationContext);
}

Expand Down Expand Up @@ -607,4 +615,28 @@ public static String getAccessKey() {
public static String getSecretKey() {
return secretKey;
}

/**
* if it is proxy bean, check if the FactoryBean is Remoting bean
*
* @param bean the bean
* @param beanName the bean name
* @return boolean boolean
*/
private Object getRemotingFactoryBean(Object bean, String beanName) {
if (!SpringProxyUtils.isProxy(bean)) {
return null;
}
//the FactoryBean of proxy bean
String factoryBeanName = getFactoryBeanName(beanName);
Object factoryBean = null;
if (applicationContext.containsBean(factoryBeanName)) {
factoryBean = applicationContext.getBean(factoryBeanName);
}
return factoryBean;
}

private String getFactoryBeanName(String beanName) {
return "&" + beanName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import org.springframework.context.ApplicationContext;
import org.springframework.util.Assert;


public class RemotingFactoryBeanParser extends AbstractedRemotingParser {
@Deprecated
public class RemotingFactoryBeanParser {

public ApplicationContext applicationContext;

Expand Down Expand Up @@ -54,7 +54,7 @@ protected Object getRemotingFactoryBean(Object bean, String beanName) {
return factoryBean;
}

@Override
// @Override
public boolean isReference(Object bean, String beanName) {
Object factoryBean = getRemotingFactoryBean(bean, beanName);
if (factoryBean == null) {
Expand All @@ -63,7 +63,7 @@ public boolean isReference(Object bean, String beanName) {
return DefaultRemotingParser.get().isReference(factoryBean, getFactoryBeanName(beanName));
}

@Override
// @Override
public boolean isService(Object bean, String beanName) {
Object factoryBean = getRemotingFactoryBean(bean, beanName);
if (factoryBean == null) {
Expand All @@ -72,12 +72,12 @@ public boolean isService(Object bean, String beanName) {
return DefaultRemotingParser.get().isService(factoryBean, getFactoryBeanName(beanName));
}

@Override
// @Override
public boolean isService(Class<?> beanClass) throws FrameworkException {
return false;
}

@Override
// @Override
public RemotingDesc getServiceDesc(Object bean, String beanName) throws FrameworkException {
Object factoryBean = getRemotingFactoryBean(bean, beanName);
if (factoryBean == null) {
Expand All @@ -90,7 +90,7 @@ private String getFactoryBeanName(String beanName) {
return "&" + beanName;
}

@Override
// @Override
public short getProtocol() {
return 0;
}
Expand Down
Loading