You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/07/09 08:40:38 UTC
[GitHub] yunxiyi opened a new issue #2052: dubbo 整合spring boot 的时候报错
yunxiyi opened a new issue #2052: dubbo 整合spring boot 的时候报错
URL: https://github.com/apache/incubator-dubbo/issues/2052
dubbo 整合spring boot,在启动的时候发生死锁。在MulticastRegistry 在registered的时候。创建invoker过程中 ,会将MonitorFacotry注入MonitorFilter中。在取MonitorFacotry值时,首先会去SpiExtensionFactory 获取值,如果这里没有获取到;会到SpringExtensionFactory获取,SpringExtensionFactory 这个时候会触发ObjectFactory提前初始化。
`protected Object getSingleton(String beanName, boolean allowEarlyReference) {
Object singletonObject = this.singletonObjects.get(beanName);
if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) {
synchronized (this.singletonObjects) {
singletonObject = this.earlySingletonObjects.get(beanName);
if (singletonObject == null && allowEarlyReference) {
ObjectFactory<T> singletonFactory = this.singletonFactories.get(beanName);
if (singletonFactory != null) {
singletonObject = singletonFactory.getObject();
this.earlySingletonObjects.put(beanName, singletonObject);
this.singletonFactories.remove(beanName);
}
}
}
}
return singletonObject;
}`
这里会锁住所有对象,而被controller注解的,就是其中一员。
`@Controller("/data")
public class DataController {
@Reference(check = false)
DemoService demoService;
@PostConstruct
public void init() {
demoService.sayHello("hello world");
}
@RequestMapping("/info")
@ResponseBody
public Object info() {
Map<String, Object> map = new HashMap<>();
map.put("message", "134");
return map;
}
}`
这个时候就可能产生死锁。因为main 线程可能正在执行创建bean
被 SPI 注解的接口不应该从SpringExtensionFactory 中获取代理对象。
所以这里修改了SpringExtensionFactory 的getExtension 的方法。
`public <T> T getExtension(Class<T> type, String name) {
//SPI never get from spring bean factory
if (type.isInterface() && type.isAnnotationPresent(SPI.class)) {
ExtensionLoader<T> loader = ExtensionLoader.getExtensionLoader(type);
if (!loader.getSupportedExtensions().isEmpty()) {
return loader.getAdaptiveExtension();
}
return null;
}
for (ApplicationContext context : contexts) {
if (context.containsBean(name)) {
Object bean = context.getBean(name);
if (type.isInstance(bean)) {
return (T) bean;
}
}
}
logger.warn("No spring extension(bean) named:" + name + ", try to find an extension(bean) of type " + type.getName());
for (ApplicationContext context : contexts) {
try {
return context.getBean(type);
} catch (NoUniqueBeanDefinitionException multiBeanExe) {
throw multiBeanExe;
} catch (NoSuchBeanDefinitionException noBeanExe) {
if (logger.isDebugEnabled()) {
logger.debug("Error when get spring extension(bean) for type:" + type.getName(), noBeanExe);
}
}
}
logger.warn("No spring extension(bean) named:" + name + ", type:" + type.getName() + " found, stop get bean.");
return null;
}`
这个是demo的地址,dubbo provider 使用的是dubbo 2.7.0-SNAPSHOT 中的dubbo-demo-provider。
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org