If the project needs to connect to multiple ZooKeepers, define multiple dubbo:registry, the corresponding dubbo:reference and the registry specified by dubbo:service registry="registry1".
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <context:property-placeholder location="classpath*:config/dubbo.properties" ignore-unresolvable="true" /> <!-- provider application name information, this is equivalent to a name, our dubbo management page is more clear which application is exposed --> <dubbo:application name="${system.dubbo.application}"/> <!-- Use the zookeeper registry to expose the service address --> <dubbo:registry id="registry1" address="${system.dubbo.registry1}" check="false"/> <dubbo:registry id="registry2" address="${system.dubbo.registry2}" check="false"/> <!-- Expose services on port 20880 using the dubbo protocol --> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:consumer check="false" timeout="20000" /> <!-- Service to be referenced --> <dubbo:reference id="interface1" registry="registry1" interface="com.*.*.Interface1" timeout="12000" check="false" /> <dubbo:reference id="interface2" registry="registry2" interface="com.*.*.Interface2" timeout="12000" check="false" /> <!-- Service interface to be exposed --> <dubbo:service registry="registry1" interface="com.dubbo.service.IfinancePDLGateway" ref="ifinancePDLGatewayImpl" timeout="12000" /> </beans>
system.dubbo.application = ${system.dubbo.application} system.dubbo.registry1= ${system.dubbo.registry1} system.dubbo.registry2= ${system.dubbo.registry2} dubbo.reference.check = false
${} in the configuration file, see maven multi-environment configuration package
system.dubbo.application = ***_dev_service system.dubbo.registry1= zookeeper://192.168.0.81:2181 system.dubbo.registry2= zookeeper://192.168.0.82:2181