欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【springboot】springboot集成dubbo

程序员文章站 2022-07-12 20:57:09
...

前言

转载:https://my.oschina.net/u/3178270/blog/2995712

资料

服务端

  1. maven依赖
    服务端和消费端依赖相同
    <!-- dubbo -->
    <dependency>
        <groupId>com.alibaba.boot</groupId>
        <artifactId>dubbo-spring-boot-starter</artifactId>
        <version>0.2.0</version>
    </dependency>
    
    <!-- 基础依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    <!-- junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
    
  2. 服务端配置文件
    # base
    server.port=8002
    spring.application.name=sentinel-dubbo-user-provider
    
    # dubbo
    ## dubbo.application.name:注册到dubbo的服务名称
    ## dubbo.registry.address:dubbo注册地址
    ## dubbo.registry.protocol:dubbo注册协议
    ## dubbo.scan.base-packages:实现扫包范围
    ## dubbo.protocol.port:暴露到dubbo的端口
    dubbo.application.name=sentinel-dubbo-user-provider
    dubbo.registry.address=127.0.0.1:7001
    dubbo.registry.protocol=zookeeper
    dubbo.scan.base-packages=com.demo
    dubbo.protocol.port=28002
    
  3. @Service注解为dubbo注解
    import com.alibaba.dubbo.config.annotation.Service;
  4. 启动类注解
    @SpringBootApplication(scanBasePackages = "com.demo.*")
    @EnableDubbo
    

消费端

  1. maven依赖
    服务端和消费端依赖相同
    <!-- dubbo -->
    <dependency>
        <groupId>com.alibaba.boot</groupId>
        <artifactId>dubbo-spring-boot-starter</artifactId>
        <version>0.2.0</version>
    </dependency>
    
    <!-- 基础依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    <!-- junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
    
  2. 配置文件
    服务端和消费端配置不同
    # base
    server.port=8003
    spring.application.name=sentinel-client
    
    # dubbo
    ## dubbo.application.name:注册到dubbo的服务名称
    ## dubbo.registry.address:dubbo注册地址
    ## dubbo.registry.protocol:dubbo注册协议
    ## dubbo.scan.base-packages:实现扫包范围
    ## dubbo.protocol.port:暴露到dubbo的端口
    dubbo.application.name=sentinel-client
    dubbo.registry.address=127.0.0.1:7001
    dubbo.registry.protocol=zookeeper
    dubbo.consumer.timeout=5000
    
    
  3. 调用服务端
    @Reference
    private UserServiceApi userServiceApi;
    
  4. 启动类注解
    @SpringBootApplication
    @EnableDubbo
    

以上,就是全部配置。
下面是在dubbo控制台查看服务信息
【springboot】springboot集成dubbo

【springboot】springboot集成dubbo
【springboot】springboot集成dubbo

相关标签: spring boot