• SpringBoot整合Dubbo


    一、导入依赖

      

    二、生产者provider

      (1)目录展示

          

      (2)配置文件application.properties

          

      (3)DoSomeService接口     

    package com.zn.service;
    
    public interface DoSomeService {
        public String sayHi();
    }

      (4)DoSomeServiceImpl实现类

    package com.zn.service.impl;
    
    
    import com.alibaba.dubbo.config.annotation.Service;
    import com.zn.service.DoSomeService;
    import org.springframework.stereotype.Component;
    
    @Service(interfaceClass = DoSomeService.class)
    @Component
    public class DoSomeServiceImpl implements DoSomeService{
        @Override
        public String sayHi() {
            System.out.println("生产者生产的IDoSomeService服务,中的sayHi方法");
            return "SpringBoot Dubbo";
        }
    }

      (5)测试类StartDubbo

          

    四、消费者consumer

      (1)目录展示

          

      (2)配置文件application.properties

           

      (3)DoSomeService接口 

    package com.zn.service;
    
    public interface DoSomeService {
        public String sayHi();
    }

      (4)DubboController

    package com.zn.controller;
    
    import com.alibaba.dubbo.config.annotation.Reference;
    import com.zn.service.DoSomeService;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class DubboController {
    
        @Reference
        private DoSomeService doSomeService;
    
        @RequestMapping("/dubbo")
        public String dubbo(){
            String returnValue = doSomeService.sayHi();
           return returnValue;
        }
    }

      (5)测试类

         

     五、效果展示

      

      

       

  • 相关阅读:
    学习python第四天——列表方法
    昨天休息了一天,今天补上。列表学习
    第二天学习——字符串的方法
    mongodb
    linux学习篇(一)
    mysql优化
    linux服务
    vue配置服务器
    photoshop学习
    关于视图
  • 原文地址:https://www.cnblogs.com/Zzzzn/p/12039068.html
Copyright © 2020-2023  润新知