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

基于xml配置reference bean存在ReferenceBean提前初始化的问题,导致xml配置的占位符无法被替换 #643

Closed
mooseen opened this issue Dec 30, 2019 · 3 comments
Assignees
Milestone

Comments

@mooseen
Copy link

mooseen commented Dec 30, 2019

使用dubbo spring boot发现,当引入xml配置时,由于xml的reference会在beanFactoryPostProcessor阶段解析生成ReferenceBean的BeanDefinition,随后当调用getBeanNamesForType方法时
DubboConfigBeanDefinitionConflictProcessor#resolveUniqueApplicationConfigBean)
会触发遍历所有的BeanNames,并执行isTypeMatch方法,在执行isTypeMatch方法时第一步会通过newInstance方式生成ReferenceBean(getSingletonFactoryBeanForTypeCheck方法),但是newInstance方式getObjectType会返回null,之后会触发ReferenceBean提前初始化(getTypeForFactoryBean方法). 当ReferenceBean初始化完成后执行afterPropertiesSet方法,在afterPropertiesSet又会提前初始化RegistryConfig等Bean(BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext,RegistryConfig.class)),但是由于RegistryConfig等Bean是在BeanPostProcessor阶段(非BeanFactoryPostProcessor阶段)进行赋值以及参数宏替换,因此拿到的RegistryConfig要么为空(properties方式声明),要么占位符没有替换(xml方式声明),随后直接导致ReferenceBean初始化失败.

Caused by: java.lang.IllegalStateException: No registry config found or it's not a valid config! The registry config is: <dubbo:registry valid="false" zookeeperProtocol="false" prefix="dubbo.registry" />
	at org.apache.dubbo.config.AbstractInterfaceConfig.checkRegistry(AbstractInterfaceConfig.java:202) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:378) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:329) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:250) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.init(ReferenceAnnotationBeanPostProcessor.java:269) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.access$100(ReferenceAnnotationBeanPostProcessor.java:242) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildInvocationHandler(ReferenceAnnotationBeanPostProcessor.java:236) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildProxy(ReferenceAnnotationBeanPostProcessor.java:219) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:134) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.getInjectedObject(AnnotationInjectedBeanPostProcessor.java:360) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedFieldElement.inject(AnnotationInjectedBeanPostProcessor.java:540) ~[dubbo-2.7.3.jar:2.7.3]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:147) ~[dubbo-2.7.3.jar:2.7.3]
	... 17 more
@mercyblitz
Copy link
Contributor

DubboConfigBeanDefinitionConflictProcessor will be deprecated, this issue will be resolved since 2.7.5

@mercyblitz mercyblitz self-assigned this Dec 31, 2019
@mercyblitz mercyblitz added this to the 2.7.5 milestone Dec 31, 2019
@mooseen
Copy link
Author

mooseen commented Jan 2, 2020

I found this issue has not been completely solved in version 2.7.5. The eager initialization has bean solved in this version , but placeholder is not going to work in xml. #646

@shuangbofu
Copy link

你好,我也碰上类似的情况了,但是基本同样的配置两个项目,一个正常一个出现这个问题。请问你有解决这个问题吗?

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

3 participants