如果项目需要连接多个ZooKeeper,则定义多个dubbo:registry,对应的dubbo:reference与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" /> <!-- 提供方应用名称信息,这个相当于起一个名字,我们dubbo管理页面比较清晰是哪个应用暴露出来的 --> <dubbo:application name="${system.dubbo.application}"/> <!-- 使用zookeeper注册中心暴露服务地址 --> <dubbo:registry id="registry1" address="${system.dubbo.registry1}" check="false"/> <dubbo:registry id="registry2" address="${system.dubbo.registry2}" check="false"/> <!-- 用dubbo协议在20880端口暴露服务 --> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:consumer check="false" timeout="20000" /> <!-- 要引用的服务 --> <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" /> <!-- 要暴露的服务接口 --> <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
配置文件中的${},请看 maven多环境配置打包
system.dubbo.application = ***_dev_service system.dubbo.registry1= zookeeper://192.168.0.81:2181 system.dubbo.registry2= zookeeper://192.168.0.82:2181