SpringBoot整合Dubbo

一、导入依赖

SpringBoot整合Dubbo

二、生产者provider

  (1)目录展示

    SpringBoot整合Dubbo

  (2)配置文件application.properties

    SpringBoot整合Dubbo

  (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

    SpringBoot整合Dubbo

四、消费者consumer

  (1)目录展示

    SpringBoot整合Dubbo

  (2)配置文件application.properties

    SpringBoot整合Dubbo 

  (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)测试类

   SpringBoot整合Dubbo

 五、效果展示

SpringBoot整合Dubbo

SpringBoot整合Dubbo

 SpringBoot整合Dubbo

相关推荐