zk-interface
提供 实体类(必须实现序列化) 和 业务接口;
zk-userservice-provider
提供 业务接口的实现类
<?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:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<!--声明dubbo服务提供者的名称:保证唯一性-->
<dubbo:application name="007-zk-userservice-provider"/>
<!--声明dubbo使用的协议名称和端口号-->
<dubbo:protocol name="dubbo" port="20880"/>
<!--现在要使用zookeeper注册中心-->
<!--指定注册中心地址和端口号-->
<!--<dubbo:registry address="zookeeper://localhost:2181"/>-->
<!--使用linux系统中的zookeeper服务-->
<dubbo:registry address="zookeeper://192.168.154.128:2181"/>
<!--暴露服务接口-->
<dubbo:service interface="com.bjpowernode.dubbo.service.UserService" ref="userServiceImpl"/>
<!--加载接口实现类-->
<bean id="userServiceImpl" class="com.bjpowernode.dubbo.service.impl.UserServiceImpl"/>
</beans>
zk-consumer
消费者
进行服务调用
<?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:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<!--声明dubbo服务消费者名称:保证唯一性-->
<dubbo:application name="008-zk-consumer"/>
<!--指定注册中心-->
<!--<dubbo:registry address="zookeeper://localhost:2181"/>-->
<!--使用linux系统中的zookeeper服务-->
<dubbo:registry address="zookeeper://192.168.154.128:2181"/>
<!--引用远程接口服务-->
<dubbo:reference id="userService" interface="com.bjpowernode.dubbo.service.UserService"/>
</beans>