spring boot 集成dubbo

本demo使用spring boot 2.4.1版本集成 dubbo 2.7.15

1.创建maven项目及其子模块

父工程pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.lee.demo.dubbo.demo</groupId><artifactId>coupon-platform-normal-springboot</artifactId><version>1.0-SNAPSHOT</version><packaging>pom</packaging><modules><module>coupon-service-api</module><module>coupon-service-provider</module><module>user-service-api</module><module>user-service-provider</module><module>coupon-portal</module></modules><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><spring-boot.version>2.4.1</spring-boot.version><dubbo.version>2.7.15</dubbo.version></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>com.lee.demo.dubbo.demo.userapi</groupId><artifactId>user-service-api</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>com.lee.demo.dubbo.demo.couponapi</groupId><artifactId>coupon-service-api</artifactId> <version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-dependencies-zookeeper</artifactId><version>2.7.15</version><type>pom</type></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-bom</artifactId><version>${dubbo.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
</project>

2.其中coupon-service-api为接口

3.coupon-service-provider为接口实现类,注意,其启动类需要添加注解@EnableDubbo

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.lee.demo.dubbo.demo</groupId><artifactId>coupon-platform-normal-springboot</artifactId><version>1.0-SNAPSHOT</version></parent><groupId>com.lee.demo.dubbo.demo.couponprovider</groupId><artifactId>coupon-service-provider</artifactId><name>coupon-service-provider</name><description>coupon-service-provider</description><properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency> <dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-dependencies-zookeeper</artifactId><type>pom</type></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId></dependency> <dependency><groupId>com.lee.demo.dubbo.demo.couponapi</groupId><artifactId>coupon-service-api</artifactId> </dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.3.7.RELEASE</version><configuration><mainClass>com.lee.demo.dubbo.demo.CouponServiceProviderApplication</mainClass></configuration><executions><execution><id>repackage</id><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build>
</project>

配置文件

实现类添加注解@DubboService

4.coupon-portal为web访问层,配置如下

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.lee.demo.dubbo.demo</groupId><artifactId>coupon-platform-normal-springboot</artifactId><version>1.0-SNAPSHOT</version></parent><groupId>com.lee.demo.dubbo.demo.portal</groupId><artifactId>coupon-portal</artifactId><name>coupon-portal</name><description>coupon-portal</description><properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency> <dependency><groupId>com.lee.demo.dubbo.demo.userapi</groupId><artifactId>user-service-api</artifactId></dependency> <dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-dependencies-zookeeper</artifactId><type>pom</type></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.3.7.RELEASE</version><configuration><mainClass>com.lee.demo.dubbo.demo.CouponPortalApplication</mainClass></configuration><executions><execution><id>repackage</id><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>

启动类

 controller访问层,属性注入时,如果为RPC调用,则需要添加注解@DubboReference

5.依次启动接口提供者(springboot项目)coupon-service-provider、user-service-provider以及web层coupon-portal

6.前端访问:127.0.0.1:8080/coupon

 

至此完成了springboot 2.4.1集成 dubbo 2.7.15

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/18715.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何在海外进行A/B测试

A/B测试是对应用的各个版本进行实验&#xff0c;以分析用户如何与其交互的有效过程&#xff0c;它能够帮助我们改进关键指标&#xff0c;例如参与度或应用内购买&#xff0c;以及推出新功能&#xff0c;从而最大限度地降低大规模流失用户的风险。 A/B测试和ASO优化通常适用于应…

Android Jetpack Compose多平台用于Android和IOS

Android Jetpack Compose多平台用于Android和IOS JetBrains和外部开源贡献者已经努力工作了几年时间来开发Compose Multiplatform&#xff0c;并最近发布了适用于iOS的Alpha版本。自然地&#xff0c;我们对其功能进行了测试&#xff0c;并决定通过使用该框架在iOS上运行我们的…

分布式搜索--elasticsearch

一、初识 elasticsearch 1. 了解 ES ① elasticsearch 是一款非常强大的开源 搜索引擎&#xff0c;可以帮助我们从海量数据中 快速找到需要的内容 ② elasticsearch 结合 kibana、Logstash、 Beats&#xff0c;也就是 elastic stack (ELK)&#xff0c;被 广泛应用在日志数据分…

架构师日记-到底该如何搭建一个新系统 | 京东云技术团队

一 前言 架构设计按照实施过程可分为工程架构&#xff0c;业务架构&#xff0c;部署架构等多个维度&#xff0c;一个好的系统架构标准应该具备可扩展、可维护、可靠性、安全性和高性能等特点。尽管这些特点大家都熟知&#xff0c;但在实际落地时&#xff0c;我们更为迫切的想知…

pytorch线性模型 学习前要学习的基础知识

跟着刘二大人学pytorch&#xff0c;补全一下我的基础缺失 1.numpy基础 import numpy as np from PIL import Image anp.array([1,2,3]) #生成一维数组 print(a) bnp.arange(1,4)#创建等差数组&#xff0c;默认等差是1&#xff0c;数组为1&#xff0c;2&#xff0c;3&#xff0…

Efficient Methods for Non-stationary Online Learning

Dynamic regret Adaptive regret 假设&#xff1a; 算法过程&#xff1a; Regret分析

D. Pairs of Segments

Problem - D - Codeforces 思路&#xff1a;其实它求的就是不相交区间的最大数量&#xff0c;但是它的区间是两个区间合并得到&#xff0c;所以我们可以直接将所有能合并的区间直接合并&#xff0c;然后做一遍不相交区间的最大数量&#xff0c;这样存在一种问题就是一个区间会不…

SolidWorks二次开发-BOM球标和材料表

目标先到100&#xff0c;实在没什么好写的了&#xff0c;先把这两个简单的功能列一下吧。 private void btnInsertBalloon_Click(object sender, EventArgs e){//插入对应的BOM气泡球 球标//操作步骤->选中视图&#xff0c;执行自动球标命令SldWorks swApp Utility.Conne…

Flowable边界事件-定时边界事件

定时边界事件 定时边界事件一、定义1. 图形标记2. 完整的流程图3. XML标记 二、测试用例2.1 定时边界事件xml文件2.2 定时边界事件测试用例 总结 定时边界事件 一、定义 时间达到设定的时间之后触发事件 由于定时边界事件和开始定时事件几乎差不多&#xff0c;四种情况我就不一…

linux入门练级篇 第三讲 基本指令3

&#x1f388;个人主页:&#x1f388; :✨✨✨初阶牛✨✨✨ &#x1f43b;推荐专栏1: &#x1f354;&#x1f35f;&#x1f32f;C语言初阶 &#x1f43b;推荐专栏2: &#x1f354;&#x1f35f;&#x1f32f;C语言进阶 &#x1f511;个人信条: &#x1f335;知行合一 &#x1f…

揭秘Dalio全天候策略:基于中美市场ETF的量化回测

01 引言 Ray Dalio 是全球最大的对冲基金——桥水联合基金&#xff08;Bridgewater Associates&#xff09;的创始人和首席投资官&#xff0c;其投资哲学在金融界中广为人知。他开创了一种被称为"全天候策略"&#xff08;All Weather Strategy&#xff09;的投资策略…

【微信小程序-uniapp】CustomPicker 自定义单项选择器组件

1. 效果图 2. 组件完整代码 <template><view class="custom-picker"><view :class=<