-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
When configure dubbo service or reference bean by xml, the placeholder will not be replaced by user defined properties. if registry config not configured by dubbo.registries.<registry id> or has no default service registry config, it will throw an exception:
Caused by: java.lang.IllegalStateException: No registry config found or it's not a valid config! The registry config is: <dubbo:registry valid="false" id="registry2" prefix="dubbo.registries." />
at org.apache.dubbo.config.AbstractInterfaceConfig.checkRegistry(AbstractInterfaceConfig.java:177)
at org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:306)
at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:266)
at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:151)
at org.apache.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:68)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171)
... 88 moreIf we have default registry config (dubbo.registry.xxx), the reference bean defined in xml will using the default registry config even though we have configured registry in xml. if there is no default resgistry config, but configured by dubbo.registries.<registry id>,reference bean will using registry config defined by dubbo.registries if registry id was the same.
In both cases, the registry config defined in xml are not going to work and ignored by dubbo.
Following configuration can reproduce these exception described above.
- Dubbo: 2.7.5
- Dubbo Spring Boot : 2.7.5
- Spring Boot : 2.2.2.RELEASE
case 1
This config will cause No registry config found or it's not a valid config.
application.properties
dubbo.application.id=demo
dubbo.application.name=demo
# true or false has no effect
#dubbo.config.multiple=true
dubbo.registries.registry1.id=registry1
dubbo.registries.registry1.address=zookeeper://localhost:2181
dubbo.registries.registry1.file=/Users/test/dubbo/registry/registry1
# this config is not working
dubbo.demo.registry=zookeeper://localhost:2181
dubbo.registry.file.path=/Users/test/dubbo/registry/registry2biz-consumer.xml
<dubbo:registry id="registry2" address="${dubbo.demo.registry}" file="${dubbo.registry.file.path}" protocol="dubbo" version="1.0.0"/>
<dubbo:reference id="demoService2" registry="registry2" interface="io.test.dubbo.demo.api.DemoService" protocol="dubbo" version="1.0.0" check="false"/>
<bean id="barService" class="io.test.dubbo.demo.consumer.client.BarServiceImpl">
<property name="demoService" ref="demoService2"/>
</bean>case 2
This config will cause reference bean using default registry config even if we define it in XML.
application.properties
dubbo.application.id=demo
dubbo.application.name=demo
# default resgistry
# reference bean will use default registry config even if registry id are different.
dubbo.registry.id=registry1
dubbo.registry.address=zookeeper://localhost:2181
dubbo.registry.file=/Users/test/dubbo/registry/default
# this configuration is not going to work
dubbo.demo.registry=zookeeper://localhost:2181
dubbo.registry.file.path=/Users/test/dubbo/registry/registry2biz-consumer.xml
<dubbo:registry id="registry2" address="${dubbo.demo.registry}" file="${dubbo.registry.file.path}" protocol="dubbo" version="1.0.0"/>
<dubbo:reference id="demoService2" registry="registry2" interface="io.test.dubbo.demo.api.DemoService" protocol="dubbo" version="1.0.0" check="false"/>
<bean id="barService" class="io.test.dubbo.demo.consumer.client.BarServiceImpl">
<property name="demoService" ref="demoService2"/>
</bean>case 3
This config will cause reference bean using registry defined by dubbo.resgisties.xxx
application.properties
dubbo.application.id=demo
dubbo.application.name=demo
dubbo.config.multiple=true
# registry 1 config
dubbo.registries.registry1.id=registry1
dubbo.registries.registry1.address=zookeeper://localhost:2181
dubbo.registries.registry1.file=/Users/test/dubbo/registry/registry1
# registry 2 config
# reference bean defined in xml will use this registry as registry id are the same
dubbo.registries.registry2.id=registry2
dubbo.registries.registry2.address=zookeeper://localhost:2181
dubbo.registries.registry2.file=/Users/test/dubbo/registry/registry2
# this config is still not going to work
dubbo.demo.registry=zookeeper://localhost:2181
dubbo.registry.file.path=/Users/test/dubbo/registry/registry2_xmlbiz-consumer.xml
<dubbo:registry id="registry2" address="${dubbo.demo.registry}" file="${dubbo.registry.file.path}" protocol="dubbo" version="1.0.0"/>
<dubbo:reference id="demoService2" registry="registry2" interface="io.test.dubbo.demo.api.DemoService" protocol="dubbo" version="1.0.0" check="false"/>
<bean id="barService" class="io.test.dubbo.demo.consumer.client.BarServiceImpl">
<property name="demoService" ref="demoService2"/>
</bean>