springboot集合dubbo依赖

springboot集合dubbo依赖

  1. 创建接口工程

  2. 创建生产者

    com.thy
    021-interface-api
    1.0-SNAPSHOT

     <!--dubbo依赖 -->
     <!-- https://mvnrepository.com/artifact/org.apache.dubbo/dubbo-spring-boot-starter -->
     <dependency>
         <groupId>org.apache.dubbo</groupId>
         <artifactId>dubbo-spring-boot-starter</artifactId>
         <version>2.7.8</version>
     </dependency>
    
     <!-- https://mvnrepository.com/artifact/org.apache.dubbo/dubbo-dependencies-zookeeper -->
     <dependency>
         <groupId>org.apache.dubbo</groupId>
         <artifactId>dubbo-dependencies-zookeeper</artifactId>
         <version>2.7.8</version>
         <type>pom</type>
         <exclusions>
             <exclusion>
                 <groupId>org.slf4j</groupId>
                 <artifactId>slf4j-log4j12</artifactId>
             </exclusion>
         </exclusions>
     </dependency>
    

    添加依赖项 添加配置文件
    spring.application.name=studentservice-provice
    dubbo.scan.base-packages=com.thy.service
    dubbo.registry.address=zookeeper://localhost:2181

实现类上添加注解
@DubboService(interfaceClass = StudentService.class,version = “1.0”,timeout = 5000)
public class StudentServiceImpl implements StudentService
去实现接口

  1. 同样添加依赖并添加配置文件
    spring.application.name=consumer-application
    server.port=8081
    dubbo.registry.address=zookeeper://localhost:2181

controller类
@RestController
public class DubboController {

// @DubboReference(interfaceClass = StudentService.class,version = “1.0”)
@DubboReference(version = “1.0”)
private StudentService service;

@GetMapping("/query")
public String queryStudent(Integer id){
    Student student=service.queryStudent(id);
    return "调用远程接口,获取对象"+student.toString();
}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值