(1)dubbo实践-快速入门

目录

1、先建一个普通的springmvc项目

2、然后对其进行改造-dubbo-service

2.1、@Service应用包改为dubbo

 2.2、resources/spring/applicationContext.xml

2.3、webapp加入

3、然后对其进行改造-dubbo-web

3.1、首先把dubbo-service中的接口提出来

3.2、dubbo-service和dubbo-web引用

3.3、远程注入

3.4、src\main\resources\spring\springmvc.xml

3.5、删除web.xml-spring配置

3.6、报错处理

 4、dubbo-admin部署安装



1、先建一个普通的springmvc项目

2、然后对其进行改造-dubbo-service

注:本案例中zookeeper版本为3.5.6

    <properties>
        <spring.version>5.1.9.RELEASE</spring.version>
        <dubbo.version>2.7.4.1</dubbo.version>
        <zookeeper.version>4.0.0</zookeeper.version>
        <java.version>1.8</java.version>
    </properties>


        <!--Dubbo的起步依赖,版本2.7之后统一为org.apache.dubb -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo</artifactId>
            <version>${dubbo.version}</version>
        </dependency>
        <!--ZooKeeper客户端实现 -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>${zookeeper.version}</version>
        </dependency>
        <!--ZooKeeper客户端实现 -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>${zookeeper.version}</version>
        </dependency>

 把dubbo-service从jar项目改为war项目

<packaging>war</packaging>

具体步骤:

2.1、@Service应用包改为dubbo

 2.2、resources/spring/applicationContext.xml

    <!--    spring配置扫描包-->
    <!--    <context:component-scan base-package="com.steven.service"/>-->

    <!--dubbo配置    -->
    <!--1.配置项目名称-->
    <dubbo:application name="dubbo-service"/>
    <!--2.配置注册中心地址-->
    <dubbo:registry address="zookeeper://192.168.10.11:2181"/>
    <!--3.dubbo扫描的包-->
    <dubbo:annotation package="com.steven.service.impl"/>

注意<context:component-scan base-package="com.steven.service"/>要注释掉

2.3、webapp加入

这是个web项目,那就要加入webapp

把springmvc的项关配置删掉,仅留spring配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

		 
	<!-- spring -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:spring/applicationContext*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
</web-app>

 启动项目

3、然后对其进行改造-dubbo-web

3.1、首先把dubbo-service中的接口提出来

3.2、dubbo-service和dubbo-web引用

        <dependency>
            <groupId>com.steven</groupId>
            <artifactId>dubbo-interface</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

3.3、远程注入

3.4、src\main\resources\spring\springmvc.xml

    <!--注解驱动打开-->
    <mvc:annotation-driven/>
    <!--扫描包-->
    <context:component-scan base-package="com.steven.controller"/>

    <!--dubbo配置    -->
    <!--1.配置项目名称-->
    <dubbo:application name="dubbo-web"/>
    <!--2.配置注册中心地址-->
    <dubbo:registry address="192.168.10.11:2181"/>
    <!--3.dubbo扫描的包-->
    <dubbo:annotation package="com.steven.controller"/>

3.5、删除web.xml-spring配置

3.6、报错处理

 

 4、dubbo-admin部署安装

 

 

 

如果要加入元数据配置,在dubbo-service中配置:

 效果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值