Dubbox服务消费方如何开发-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

Dubbox服务消费方如何开发

今天就跟大家聊聊有关Dubbox服务消费方如何开发,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于成都做网站、成都网站设计、隆林网络推广、小程序开发、隆林网络营销、隆林企业策划、隆林品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联公司为所有大学生创业者提供隆林建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com

1、创建maven工程(打包方式为war)dubbodemo_consumer,pom.xml配置和上面服务提供者相同,只需要将Tomcat插件的端口号改为8082即可。

 

2、配置web.xml文件

 

~~~xml

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

 "http://java.sun.com/dtd/web-app_2_3.dtd" >

  Archetype Created Web Application

 

    springmvc

    org.springframework.web.servlet.DispatcherServlet

   

   

      contextConfigLocation

      classpath:applicationContext-web.xml

    

    1

 

 

    springmvc

    *.do

 

~~~

 

3、将服务提供者工程中的HelloService接口复制到当前工程

 

4、编写Controller

 

~~~java

package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;

import com.itheima.service.HelloService;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

 

@Controller

@RequestMapping("/demo")

public class HelloController {

    @Reference

    private HelloService helloService;

 

    @RequestMapping("/hello")

    @ResponseBody

    public String getName(String name){

        //远程调用

        String result = helloService.sayHello(name);

        System.out.println(result);

        return result;

    }

}

~~~

 

注意:Controller中注入HelloService使用的是Dubbo提供的@Reference注解

 

5、在src/main/resources下创建applicationContext-web.xml

 

~~~xml

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xmlns:p="http://www.springframework.org/schema/p"

         xmlns:context="http://www.springframework.org/schema/context"

         xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

         xmlns:mvc="http://www.springframework.org/schema/mvc"

         xsi:schemaLocation="http://www.springframework.org/schema/beans

                            http://www.springframework.org/schema/beans/spring-beans.xsd

                            http://www.springframework.org/schema/mvc

                            http://www.springframework.org/schema/mvc/spring-mvc.xsd

                            http://code.alibabatech.com/schema/dubbo

                            http://code.alibabatech.com/schema/dubbo/dubbo.xsd

                            http://www.springframework.org/schema/context

                            http://www.springframework.org/schema/context/spring-context.xsd">

 

        

        

        

        

        

        

~~~

 

6、运行测试

 

tomcat7:run启动

 

在浏览器输入http://localhost:8082/demo/hello.do?name=Jack,查看浏览器输出结果。

看完上述内容,你们对Dubbox服务消费方如何开发有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


文章题目:Dubbox服务消费方如何开发
URL地址:http://kswsj.cn/article/pjeocj.html

其他资讯