Dubbo 暴露服务

1. 引入dubbo依赖

     dubbo 依赖
<dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.6.2</version> </dependency>
zookeeper 依赖 客户端
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.12.0</version>
</dependency>

2. xml配置

<?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://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!--1. 指定当前服务的名字-->
    <dubbo:application name="Dubbo-server"/>

    <!--2. 指定注册中心的位置-->
    <dubbo:registry protocol="zookeeper" address="124.0.0.1:2181"></dubbo:registry>

    <!--3. 指定通信规则(通信协议?通信端口)-->
    <dubbo:protocol name="dubbo" port="20880"></dubbo:protocol>

    <!--4. 暴露服务,指向服务的真正实现对象-->
    <dubbo:service interface="com.aynu.service.UserService" ref="userServiceImpl"></dubbo:service>

    <!--服务的实现-->
    <bean id="userServiceImpl" class="com.aynu.service.UserServiceImpl"></bean>
</beans>

 

上一篇:ZooKeeper学习之路(四)—— Java 客户端 Apache Curator


下一篇:java.lang.NoSuchMethodError: org.apache.curator.framework.api.CreateBuilder.creatingParentsIfNeeded(