wujun27 commented on issue #10278:
URL: https://github.com/apache/dubbo/issues/10278#issuecomment-1176370697
dubbo是在启动模块demo-application加入的dubbo依赖, Root Spring
context触发了org.apache.dubbo.config.spring.context.DubboSpringInitializer#initialize,这块是没问题的。
接下来demo-service是个sofa module,sofa会给这个模块初始化一个独立的Spring 上下文,
demo-service这个模块因为没有dubbo依赖,所以不会触发org.apache.dubbo.config.spring.context.DubboSpringInitializer#initialize。
但是demo-service的子beanFactory会从父beanFactory获取postBeanProcessBeans,
所以demo-service的子beanFactory
refresh的时候会触发DubboInfraBeanRegisterPostProcessor#postProcessBeanFactory,
然而ReferenceAnnotationBeanPostProcessor在Root
Spring上下文已经被自己销毁,所以模块的子Spring上下文和RootSpring上下文都找不到这个bean,最终报No bean named
'referenceAnnotationBeanPostProcessor' available。
demo-service模块本身就没有dubbo依赖,也不需要去触发org.apache.dubbo.config.spring.context.DubboSpringInitializer#initialize。
目前在本地,我把ReferenceAnnotationBeanPostProcessor如下这段代码注释掉以后就没有没问题的。
但不确定是否会有其他影响?
、、、
if (beanFactory instanceof AbstractBeanFactory) {
List<BeanPostProcessor> beanPostProcessors =
((AbstractBeanFactory) beanFactory).getBeanPostProcessors();
for (BeanPostProcessor beanPostProcessor : beanPostProcessors) {
if (beanPostProcessor == this) {
// This bean has been registered as BeanPostProcessor at
org.apache.dubbo.config.spring.context.DubboInfraBeanRegisterPostProcessor.postProcessBeanFactory()
// so destroy this bean here, prevent register it as
BeanPostProcessor again, avoid cause BeanPostProcessorChecker detection error
beanDefinitionRegistry.removeBeanDefinition(BEAN_NAME);
break;
}
}
}
、、、
这段注释也没看特别明白,DubboInfraBeanRegisterPostProcessor也没去注册ReferenceAnnotationBeanPostProcessor
bean,只是为了保证ReferenceAnnotationBeanPostProcessor比PropertySourcesPlaceholderConfigurer先执行。
、、、
// In Spring 3.2.x, registry may be null because do not calling
postProcessBeanDefinitionRegistry method before postProcessBeanFactory
if (registry != null) {
// register ReferenceAnnotationBeanPostProcessor early before
PropertySourcesPlaceholderConfigurer/PropertyPlaceholderConfigurer
// for processing early init ReferenceBean
ReferenceAnnotationBeanPostProcessor
referenceAnnotationBeanPostProcessor = beanFactory.getBean(
ReferenceAnnotationBeanPostProcessor.BEAN_NAME,
ReferenceAnnotationBeanPostProcessor.class);
beanFactory.addBeanPostProcessor(referenceAnnotationBeanPostProcessor);
// register PropertySourcesPlaceholderConfigurer bean if not exits
DubboBeanUtils.registerPlaceholderConfigurerBeanIfNotExists(beanFactory,
registry);
}
、、、
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]