zoukankan      html  css  js  c++  java
  • springboot整合dubbo

    生产者

      结构

          

      导入依赖

        <dependency>
                <groupId>com.101tec</groupId>
                <artifactId>zkclient</artifactId>
                <version>0.10</version>
            </dependency>
    
            <dependency>
                <groupId>com.alibaba.spring.boot</groupId>
                <artifactId>dubbo-spring-boot-starter</artifactId>
                <version>2.0.0</version>
            </dependency>

      application.properties文件

    spring.dubbo.application.name=prodvice_dubbo01
    spring.dubbo.registry.address=zookeeper://127.0.0.1:2181
    spring.dubbo.protocol.name=dubbo
    spring.dubbo.protocol.port=20881
    
    spring.dubbo.scan=com.zk.boot_dubbo01.service
    
    server.port=8083

      service接口

    public interface BootService {
    
        public String getOne();
    
    }

      service接口实现

    package com.zk.boot_dubbo01.service;
    
    import com.alibaba.dubbo.config.annotation.Service;
    import org.springframework.stereotype.Component;
    
    @Service(interfaceClass = BootService.class)
    @Component
    public class BootServiceImpl implements BootService 
    
        @Override
        public String getOne() {
            return "到了---";
        }
    }

      启动类

    package com.zk.boot_dubbo01;
    
    import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    @EnableDubboConfiguration
    public class BootDubbo01Application {
    
        public static void main(String[] args) {
            SpringApplication.run(BootDubbo01Application.class, args);
            System.out.println("dfghjkjhe");
        }
    
    }

    消费者

      结构

          

      导入依赖

        <dependency>
                <groupId>com.101tec</groupId>
                <artifactId>zkclient</artifactId>
                <version>0.10</version>
            </dependency>
    
            <dependency>
                <groupId>com.alibaba.spring.boot</groupId>
                <artifactId>dubbo-spring-boot-starter</artifactId>
                <version>2.0.0</version>
            </dependency>

      application.properties文件

    spring.dubbo.application.name=consumer_dubbo01
    spring.dubbo.registry.address=zookeeper://127.0.0.1:2181
    spring.dubbo.scan=com.zk.boot_dubbo02.controller
    
    server.port=8084

      service接口(与生产者相同)

    public interface BootService {
        public String getOne();
    }

      controller层

    package com.zk.boot_dubbo01.controller;
    
    import com.alibaba.dubbo.config.annotation.Reference;
    import com.zk.boot_dubbo01.service.BootService;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    @RequestMapping("/user")
    public class UserController {
    
        @Reference
        private BootService service;
    
        @RequestMapping("/getOne")
        @ResponseBody
        public String   getOne(){
            String user = service.getOne();
            return user;
        }
    
    
    }

      启动类

    package com.zk.boot_dubbo01;
    
    import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    @EnableDubboConfiguration
    public class ApplicationStart {
    
        public static void main(String[] args) {
            SpringApplication.run(ApplicationStart.class, args);
        }
    }

    结果

      消费者能调用生产者里面的方法

      

  • 相关阅读:
    jQuery.noConflict() 函数详解
    Meta标签用法大全
    解决
    如何在同一台服务器上安装多套通达OA
    Android UI设计系统-android selector 开始自定义样式
    Android UI设计系统---LayoutParams[转]
    jquery Ajax应用总结
    阿里云主机安装Memcached
    PHP搭建OAuth2.0
    制作干净系统 批处理删除所有设备驱动
  • 原文地址:https://www.cnblogs.com/wnwn/p/12039159.html
Copyright © 2011-2022 走看看