码迷,mamicode.com
首页 > 其他好文 > 详细

Dubbo-002

时间:2018-10-06 00:57:53      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:manage   netty   sch   ESS   关系   中心   pac   name   registry   

1.引入Dubbo相关依赖:

        <dubbo.version>2.5.3</dubbo.version>
        <zookeeper.version>3.4.7</zookeeper.version>
        <zkclient.version>0.1</zkclient.version>
        
        <!-- dubbo相关 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>${dubbo.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>${zookeeper.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
            <version>${zkclient.version}</version>
        </dependency>

 

2.在service服务层发布Dubbo服务:(记得去掉与spring冲突的jar包)

        applicationContext-service.xml:
        
            <!-- 发布dubbo服务 -->
            <!-- 提供方应用信息,用于计算依赖关系 -->
            <dubbo:application name="taotao-manager" />
            <!-- 注册中心的地址 -->
            <dubbo:registry protocol="zookeeper" address="192.168.132.128:2181" />
            <!-- 用dubbo协议在20880端口暴露服务 -->
            <dubbo:protocol name="dubbo" port="20880" />
            <!-- 声明需要暴露的服务接口 -->
            <dubbo:service interface="com.taotao.service.ItemService"
                ref="itemServiceImpl" />
        pom.xml:

            <!-- dubbo相关 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>spring</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>netty</artifactId>
                    <groupId>org.jboss.netty</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>

 

3.在web视图层引用Dubbo服务:

springmvc.xml:


    <!-- 引用dubbo服务 -->
    <dubbo:application name="taotao-manager-web" />
    <dubbo:registry protocol="zookeeper" address="192.168.132.128:2181" />
    <dubbo:reference interface="com.taotao.service.ItemService"
        id="itemService" />


pom.xml:

<!-- dubbo相关 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>spring</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>netty</artifactId>
                    <groupId>org.jboss.netty</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>

 

Dubbo-002

标签:manage   netty   sch   ESS   关系   中心   pac   name   registry   

原文地址:https://www.cnblogs.com/yikuan-919/p/9746440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!