1.项目接口

2. 编辑pom.xml和application.yml文件

2.1父工程

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.10</version><relativePath/></parent><groupId>com.hanxun</groupId><artifactId>crmbe-service-backend</artifactId><packaging>pom</packaging><version>1.0</version><properties><java.version>1.8</java.version><spring.boot.version>2.7.10</spring.boot.version><dubbo.version>3.0.10</dubbo.version><nacos-client.version>2.1.1</nacos-client.version></properties><modules><module>crmbe-api</module><module>crmbe-consumer</module><module>crmbe-provider</module></modules><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId><version>${spring.boot.version}</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>${spring.boot.version}</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><version>${spring.boot.version}</version><scope>test</scope></dependency><!-- Dubbo核心依赖 --><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId><version>${dubbo.version}</version></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-registry-nacos</artifactId><version>${dubbo.version}</version><exclusions><!-- 排除适配层自带的 Nacos 客户端,避免版本冲突 --><exclusion><groupId>com.alibaba.nacos</groupId><artifactId>nacos-client</artifactId></exclusion></exclusions></dependency><!-- Nacos 客户端核心依赖 --><dependency><groupId>com.alibaba.nacos</groupId><artifactId>nacos-client</artifactId><version>${nacos-client.version}</version></dependency><dependency><groupId>com.alibaba.spring</groupId><artifactId>spring-context-support</artifactId><version>1.0.11</version></dependency><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>30.1-jre</version></dependency></dependencies></dependencyManagement>
</project>

2.2 api 模块

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.hanxun</groupId><artifactId>crmbe-service-backend</artifactId><version>1.0</version></parent><groupId>com.hanxun</groupId><artifactId>crmbe-api</artifactId><version>1.0</version><dependencies><dependency><groupId>com.alibaba.spring</groupId><artifactId>spring-context-support</artifactId></dependency></dependencies></project>

2.3 consumer 模块

代码结构:

dubbo注解:

Controller中使用 @DubboReference  进行依赖注入

@RestController
@RequestMapping("/test")
public class UserController {@DubboReference(version = "1.0")private UserService userService;@GetMapping("/get")public Object get(String id){List<SysUser> userList= userService.getUserList();//        return "hello world !!!";return userList;}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.hanxun</groupId><artifactId>crmbe-service-backend</artifactId><version>1.0</version></parent><groupId>com.hanxun</groupId><artifactId>crmbe-consumer</artifactId><version>1.0</version><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.hanxun</groupId><artifactId>crmbe-api</artifactId><version>1.0</version></dependency><!-- dubbo --><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-registry-nacos</artifactId></dependency><dependency><groupId>com.alibaba.nacos</groupId><artifactId>nacos-client</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId></dependency></dependencies><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>${spring.boot.version}</version><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>
 yml文件
# 应用名称
spring:application:name: crmbe-consumer
#  cloud:# Nacos配置中心
#    nacos:
#      server-addr: 127.0.0.1:8848 # Nacos 服务器地址
#      username: nacos # Nacos 账号
#      password: nacos # Nacos 密码
#      discovery: # 【配置中心】配置项
#        namespace: dev # 命名空间。这里使用 dev 开发环境
#        group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
#        metadata:
#          version: 1.0.0 # 服务实例的版本号,可用于灰度发布
#      config: # 【注册中心】配置项
#        namespace: dev # 命名空间。这里使用 dev 开发环境
#        group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUPconfig:import:- optional:nacos:application.yml- optional:nacos:${spring.application.name}.yml# Dubbo配置
dubbo:application:name: crmbe-consumerlogger: slf4jprotocol:name: dubboport: -1registry:address: nacos://127.0.0.1:8848parameters:namespace: dev# 服务端口
server:port: 8082servlet:context-path: /crmbe-consumer

2.4 provider模块

代码结构:

dubbo 注解:

UserSeviceImpl 使用 @DubboService 注解 暴露服务

@DubboService(version = "1.0")
public class UserSeviceImpl implements UserService {@Overridepublic List<SysUser> getUserList() {List<SysUser> userlist = new ArrayList<SysUser>();SysUser user1 = new SysUser("张三",20, LocalDateTime.now());SysUser user2 = new SysUser("李四",30,LocalDateTime.now());SysUser user3 = new SysUser("王五",31,LocalDateTime.now());userlist.add(user1);userlist.add(user2);userlist.add(user3);userlist.add(user3);return userlist;}
}

Application 类加 @EnableDubbo

@EnableDubbo
@SpringBootApplication
public class CrmbeProviderApplication {public static void main(String[] args) {SpringApplication.run(CrmbeProviderApplication.class, args);System.out.println("--------------Dubbo Provider 启动成功-----------------");}}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.hanxun</groupId><artifactId>crmbe-service-backend</artifactId><version>1.0</version></parent><artifactId>crmbe-provider</artifactId><version>1.0</version><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.hanxun</groupId><artifactId>crmbe-api</artifactId><version>1.0</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><!-- dubbo --><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-registry-nacos</artifactId></dependency><dependency><groupId>com.alibaba.nacos</groupId><artifactId>nacos-client</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId></dependency></dependencies><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><!-- 明确指定 Java 版本为 1.8 --><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>${spring.boot.version}</version><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>
 yml文件
# 应用名称
spring:application:name: crmbe-providerconfig:import:- optional:nacos:application.yml- optional:nacos:${spring.application.name}.yml# Dubbo配置
dubbo:application:name: crmbe-providerlogger: slf4jprotocol:name: dubboport: -1registry:address: nacos://127.0.0.1:8848parameters:namespace: devconfig-center:address: nacos://127.0.0.1:8848parameters:namespace: devscan:base-packages: com.hanxun# 服务端口
server:port: 8081

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

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

相关文章

android中常见布局及其约束

0 布局的定义 布局可以理解为一种​​容器​​&#xff0c;用于​​组织与排列界面上的控件​​。 布局是一个相框&#xff0c;控件就是你要展示的照片。• 你&#xff08;布局规则&#xff09;决定这些照片怎么排列&#xff1a;是从上到下整齐放&#xff08;LinearLayout&am…

Rust语言能干什么

Rust 语言的应用范围非常广&#xff0c;几乎覆盖了现代软件开发的全部领域。它最初以“系统级语言”身份出道&#xff0c;但现在已经远远超出了这个范畴。下面我从几个关键方向给你梳理一下&#xff0c;Rust 到底能干什么&#xff0c;以及为什么在这些领域它特别有优势。 1. 系…

只需一个设置就可以解决Microsoft Edge浏览器打不开网页的问题

Microsoft Edge是一款功能强大的网络浏览器&#xff0c;预装在Windows 10、11系统中。通过这个简单易懂的教程&#xff0c;学习如何修复Microsoft Edge浏览器打不开的问题。1、打开计算机找到C盘&#xff0c;双击打开&#xff1a;2、打开【用户】➜【Admin】➜【AppData】➜【L…

AI 应用 图文 解说 (二) -- 百度智能云 ASR LIM TTS 语音AI助手源码

文章的目的为了记录AI应用学习的经历&#xff0c;降低AI的入门难度。同时记录开发流程和要点有些记忆模糊&#xff0c;防止忘记。也希望可以给看到文章的朋友带来一些收获。 相关链接&#xff1a; AI 应用 图文 解说 (一) -- 百度智能云 实现 语音 聊天-CSDN博客 AI 应用 图文 …

计算机Python毕业设计推荐:基于Django的博客网站设计与实现【python/大数据/深度学习/机器学习定制】

精彩专栏推荐订阅&#xff1a;在下方主页&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb; &#x1f496;&#x1f525;作者主页&#xff1a;计算机毕设木哥&#x1f525; &#x1f496; 文章目录 一、项目介绍二、…

当 AI 开始 “筛选” 信息:算法偏见会加剧认知鸿沟吗?如何构建公平的 AI 生态?

AI 筛选信息的现状与原理​在信息爆炸的时代&#xff0c;AI 筛选信息已成为各领域不可或缺的关键技术。在社交媒体平台上&#xff0c;如抖音、小红书等&#xff0c;AI 根据用户的点赞、评论、浏览历史等数据&#xff0c;精准推送用户可能感兴趣的内容&#xff0c;极大提升了用户…

2023年IEEE IOTJ SCI1区TOP,动态环境下无人机目标覆盖任务路径规划,深度解析+性能实测

目录1.摘要2.问题模型3.算法设计4.结果展示5.参考文献6.代码获取7.算法辅导应用定制读者交流1.摘要 无人机&#xff08;UAV&#xff09;作为物联网应用的重要工具&#xff0c;正广泛应用于智能农业监测、智能交通监测等领域&#xff0c;并逐渐成为国内外研究热点。然而&#x…

计算机视觉(四):二值化

二值化&#xff0c;就是将图像从彩色或灰度模式转换为只有两种颜色&#xff08;通常是黑色和白色&#xff09;的模式。这个过程的本质是设定一个阈值 (Threshold)&#xff0c;将图像中所有像素的灰度值与这个阈值进行比较。 基本原理 二值化的核心原理非常简单&#xff1a; 灰度…

(二)设计模式(Command)

文章目录项目地址一、设计模式1.1 Command Design1. 创建命令接口2. 创建支付的Command类3. CommandScheduler4. 使用1.2 Chain of Responsibility1. 接口创建2. 审批人3. 发起审批1.3 State Pattern1. 创建简单的状态机定义动作和状态状态机使用状态机1.x Iterator1.x Observe…

现代C++性能陷阱:std::function的成本、异常处理的真实开销

1. std::function 的成本 std::function 是一个通用的、类型擦除的函数包装器&#xff0c;它非常方便&#xff0c;可以存储和调用任何可调用对象&#xff08;函数、lambda、函数对象、bind表达式等&#xff09;。然而&#xff0c;这种灵活性是有代价的。 主要成本来源&#xff…

基于Spark的白酒行业数据分析与可视化系统的设计与实现

文章目录有需要本项目的代码或文档以及全部资源&#xff0c;或者部署调试可以私信博主项目介绍一、项目背景与研究意义二、系统整体架构三、系统功能设计四、应用场景与价值五、项目特色与创新点六、总结与展望每文一语有需要本项目的代码或文档以及全部资源&#xff0c;或者部…

织梦会员中心模板调用某个栏目名和栏目下文档的办法

大家在用到织梦dedecms时候&#xff0c;需要在会员中心模板调用栏目的名称和链接&#xff0c;还有某个栏目下的文档要怎么操作呢&#xff1f; 我们都知道&#xff0c;在会员中心模板&#xff0c;直接用dede:type或者dede:arclist标签是不行的&#xff0c;在会员中心调用只能用p…

区块链的法律定位:技术、工具还是资产?

高鹏律师首席数据官&#xff0c;数字经济团队创作AI辅助当我们谈论区块链时&#xff0c;我们在谈论什么&#xff1f;是那串不可篡改的哈希值&#xff0c;是去中心化的信仰图腾&#xff0c;还是藏在代码背后的权利密码&#xff1f;今天&#xff0c;我们不聊技术迭代的炫酷&#…

LeetCode每日一题,2025-8-31

dfs搜索解数独&#xff0c;重点是如何判断当前这位置的board[x][y]是否可以填数字num public class T37 {public static void main(String[] args) {char[][] board new char[][]{{5, 3, ., ., 7, ., ., ., .},{6, ., ., 1, 9, 5, ., ., .},{., 9, 8, ., ., ., ., 6, .},{8, …

Linux 进程信号学习笔记:从概念到实操

一、Linux 信号基本概念1.1 生活角度理解信号我们可以把进程比作等待快递的人&#xff0c;信号就像快递&#xff1a;识别信号&#xff1a;就像我们知道快递来了该 怎么处理&#xff0c;进程对信号的识别是内核程序员预先编写的内置特性&#xff0c;即使信号没产生&#xff0c;进…

解决多种类潮湿敏感元器件的多温度、多时长的排潮烘干

铠德科技ESD烘箱针对复杂电路产品的排潮烘干需求&#xff0c;可通过以下技术路径实现多品类元器件的高效兼容处理&#xff1a;多温区独立控制系统采用蜂窝式加热模块阵列&#xff0c;每个0.6m独立温区可设置1℃精度支持同时运行3种不同温度曲线&#xff08;典型值&#xff1a;8…

obdumper和obloader迁移OceanBase业务库(一):实施手册

obdumper和obloader迁移OceanBase业务库&#xff08;一&#xff09;&#xff1a;实施手册导出前准备全库&#xff08;模式&#xff09;数据导出全库&#xff08;模式&#xff09;数据导入导入后检查环境信息&#xff1a;OceanBase v4.3.5单机部署&#xff0c;MySQL租户OBDUMPER…

SQLSugar 快速入门:从基础到实战查询与使用指南

目录 ​编辑 一、SQLSugar 简介 二、SQLSugar 环境搭建 2.1 安装 SQLSugar 2.1.1 通过 Visual Studio NuGet 图形化界面安装 2.1.2 通过 NuGet 命令行安装 2.2 引用 SQLSugar 命名空间 三、SQLSugar 核心初始化配置 3.1 基础初始化&#xff08;非 IOC 模式&#xff09…

Python与Rust语法对比详解:从入门到精通

Python与Rust语法对比详解&#xff1a;从入门到精通 前言 Python和Rust作为当今最受关注的编程语言&#xff0c;分别代表了动态类型和静态类型语言的典型特征。本文将从语法层面深入对比这两种语言&#xff0c;帮助开发者理解它们的设计理念和使用场景。1. 基础语法结构 1.1 He…

视频加水印_带gif 加动态水印 gif水印 视频浮动水印

如果你有一个视频&#xff0c;你想给它加一个水印&#xff0c;让水印浮动&#xff0c;而且加的还是 GIF 动态图片水印&#xff0c;那么你可以使用这个工具。首先把你的两个文件拖进来&#xff0c;然后点击第三个按钮。加好了&#xff0c;打开看一下&#xff0c;我们看到这个水印…