首页 > 其他分享 >springboot整合dubbo

springboot整合dubbo

时间:2023-06-30 19:32:17浏览次数:52  
标签:dubbo springboot boot 引入 整合 org apache import



导航

  • 了解dubbo
  • 引入依赖
  • 编写服务提供模块
  • 编写服务消费模块
  • dubbo-admin安装
  • 源码github上
  • 参考


了解dubbo

springboot整合dubbo_github


后面被捐赠给了apache基金会,已经毕业了好像…官网: https://dubbo.apache.org/zh/docs/introduction/ 官网介绍的很详细了,具体见官网上面的信息.

引入依赖

可以参考官方文档:
https://github.com/apache/dubbo-spring-boot-project/blob/master/README_CN.md

<!-- 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.0</version>
        </dependency>
           <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.7.1</version>
        </dependency>
         <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>2.13.0</version>
        </dependency>

编写服务提供模块

我是在自己以前搭建的一个springboot模块项目里面搭建的…

首先建一个接口模块,因为,服务的提供者和消费者都需要引入这个接口包,当然dubbo也可以通过泛化调用就不需要引入接口包了,那一块没过多了解,有兴趣的时候在弄好了.

springboot整合dubbo_spring boot_02


随便建个方法,然后编写个provider,引入interface模块:写个TestDubboService接口的实现类:注意引入的包是dubbo的包.

springboot整合dubbo_github_03

import com.mr.interfaces.test.TestDubboService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;



/**
 * @ClassName TestDubboServiceImpl
 * @Description dubbo测试接口的实现类
 * @Author stack
 * @Version 1.0
 * @since 2019/6/21 10:20
 */
@Component
@Service(version = "1.0",timeout = 10000,interfaceClass = TestDubboService.class)
public class TestDubboServiceImpl implements TestDubboService {

    @Override
    public String testDubbo(String s) {
        return "dubbo测试接口的实现类";
    }
}

一般的话,privider里面依赖dao然后连接数据库等等,这里的话,就不这么干了,就按照官方demo写个简单的测试好了…然后启动报错:可能原因The bean ‘dubboConfigConfiguration.Single’, defined in null 然后编写main方法:

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootVersion;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.time.Duration;
import java.time.Instant;

/**
 * 启动程序
 */
@SpringBootApplication
@EnableDubbo
public class MyProjectApplication {

    private static final Logger log = LoggerFactory.getLogger(MyProjectApplication.class);

    public static void main(String[] args) {
        Instant inst1 = Instant.now();
        SpringApplication.run(MyProjectApplication.class, args);
        log.info("基于 Spring Boot {} ", SpringBootVersion.getVersion());
        log.info("启动成功!耗时:{}秒 ", Duration.between(inst1, Instant.now()).getSeconds());
    }

}

zk记得打开,启动成功

编写服务消费模块

原来的项目里面有web,我就直接写在web模块里面好了

首先在web的pom里面引入dubbo接口包

springboot整合dubbo_zookeeper_04


然后在controller里面注入接口里面类:

springboot整合dubbo_spring_05


服务消费者配置跟提供者配置差不多,注意我们使用的是注解,@Reference,引入的包import org.apache.dubbo.config.annotation.Reference;

然后请求方法,成功了,注意,dubbo调用可以debug的.

springboot整合dubbo_zookeeper_06


不知道为啥使用apache-dubbo包总是要多导入curator-recipes这个包,这个包大概就是apache官方操作zk使用的包,然后dubbo如果使用zk作为注册中心,就需要引入这个包.

记得引入:

<dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>2.13.0</version>
        </dependency>

dubbo-admin安装


然后访问,就可以看到对应的提供者消费者啦…

springboot整合dubbo_zookeeper_07

源码github上

其实我喜欢引入springboot阿里巴巴dubbo…配置都差不多,省去一些错误好像.
https://github.com/stackXu/springboot-study

参考

官网:http://dubbo.apache.org/zh-cn/docs/user/quick-start.html
官方demo:https://github.com/apache/dubbo-spring-boot-project/tree/master/dubbo-spring-boot-samples

标签:dubbo,springboot,boot,引入,整合,org,apache,import
From: https://blog.51cto.com/u_16174475/6592984

相关文章

  • springboot操作redis
    添加依赖<!--springboot操作redis依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency> 在ap......
  • SpringBoot elasticsearch 简单使用
    ElasticSearch是一个基于Lucene的搜索服务器,其实就是对Lucene进行封装,提供了RESTAPI的操作接口。ElasticSearch作为一个高度可拓展的开源全文搜索和分析引擎,可用于快速地对大数据进行存储,搜索和分析。ElasticSearch主要特点:分布式、高可用、异步写入、多API、面向文档。Elastic......
  • 【SpringBoot】RedisTemplate自动注入失败原因及解决方案
    报错:packagecom.example.springdataredisdemo;importorg.junit.jupiter.api.Test;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.boot.test.context.SpringBootTest;importorg.springframework.data.redis.co......
  • 基于SpringBoot搭建WebSocker
    1.添加pom依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupI......
  • Doris整合Elasticsearch
    1、环境doris 1.2.4Elasticsearch7.7安装教程https://www.cnblogs.com/yanzhong/p/17515917.html2、doris配置外表(方法一)1、添加语法详细官网https://doris.apache.org/zh-CN/docs/1.2/lakehouse/external-table/es?_highlight=外表#doris中创建es外表CREATEEXTE......
  • springboot 配置mybatis打印sql
    方式一:###########################################################配置打印sql########################################################logging:level:com.threefivework.mymall.dao.mapper:DEBUG//包路径为mapper文件包路径方式二:在application.yml......
  • springboot启动取消数据源
    pom.xml中取消数据库相关的配置,maven的相关的数据库依赖包删除,右击项目openmodulesettings ......
  • SpringBoot--尚硅谷2018
    #一、SpringBoot入门B站视频地址:72_尚硅谷_结束语_哔哩哔哩_bilibili1、SpringBoot简介简化Spring应用开发的一个框架;整个Spring技术栈的一个大整合;J2EE开发的一站式解决方案;2、微服务2014,martinfowler微服务:架构风格(服务微化)一个应用应该是一组小型服务;可以通......
  • 【SpringBoot】redis keys命令被禁用,spring缓存 @CacheEvict报异常
     背景项目使用springboot整合redis做缓存,代码中使用spring的缓存注解配置缓存策略。在jarvis上部署时接入了公司分布式redis平台代替本地的redis。结果测试的时候,新增一条记录时报了错,提示  ERRunknowncommand'keys' 。经排查发现问题原因:新增记录的函数上有@C......
  • Springboot配置优先级
    #图片来自转载最后的优先级就是:命令行参数>java系统属性>application.properties>application.yml>application.yaml......