当前位置: 首页 > news >正文

异构微服务远程调用如何打jar包

1.服务提供方打 jar 包

RemoteUserService.java

package com.finance.system.api;import com.finance.system.api.domain.dto.Enterprise;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import com.finance.common.core.constant.ServiceNameConstants;
import com.finance.common.core.domain.R;
import com.finance.system.api.factory.RemoteUserFallbackFactory;
import com.finance.system.api.model.LoginUser;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;/*** 用户服务*/
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
public interface RemoteUserService
{/*** 同步公司数据*/@PostMapping(value = "/company/registerEnterprise")public R registerEnterprise(@RequestBody Enterprise enterprise);
}
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-assembly-plugin</artifactId><version>3.3.0</version><configuration><descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs><!-- 这里可以没有主类,作为工具包使用 -->
<!--                    <archive>-->
<!--                        <manifest>-->
<!--                            <mainClass>com.example.MainClass</mainClass>-->
<!--                        </manifest>-->
<!--                    </archive>--></configuration><executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions></plugin></plugins>
</build>

Maven Assembly Plugin 是一个用于创建可执行的分发包的 Maven 插件。它可以将项目的依赖和资源文件打包成一个可执行的分发包,方便部署和使用。

当运行 mvn package 命令时,Maven Assembly Plugin 将会执行,并生成分发包。

完成配置后,您可以运行以下命令来生成分发包:

mvn package

生成的分发包将会位于项目的 target 目录下,后缀为 jar-with-dependencies.jar,这里是 finance-api-system-2.5.0-jar-with-dependencies.jar,里面已经包含了项目和它的所有依赖。

2.服务调用方引用 jar 包

<!-- 引用异构服务jar包 -->
<dependency><groupId>com.finance</groupId><artifactId>finance-api-system</artifactId><version>2.5.0</version><scope>system</scope><systemPath>${basedir}/lib/finance-api-system-2.5.0-jar-with-dependencies.jar</systemPath>
</dependency>

调用方需扫描远程类所在路径

@EnableFeignClients(basePackages = {"com.finance.system.api"})
@Resource
private RemoteUserService remoteUserService;R result = remoteUserService.registerEnterprise(enterprise);
log.info("result: {}", result);
// result: {msg=操作成功, code=200}
http://www.lryc.cn/news/277789.html

相关文章:

  • 赋能智慧农业生产,基于YOLOv7开发构建农业生产场景下油茶作物成熟检测识别系统
  • Docker入门介绍
  • 第四站:指针的进阶-(二级指针,函数指针)
  • 浏览器渲染原理(面试重点)
  • C //练习 5-3 用指针方式实现第2章中的函数strcat。函数strcat(s, t)将t指向的字符串复制到s指向的字符串的尾部。
  • 深度剖析Redis:从基础到高级应用
  • 视频监控录像服务器(中心录像服务器)功能详细介绍
  • SouthernBiotech抗荧光淬灭封片剂
  • [Excel]如何找到非固定空白格數列的條件數據? 以月份報價表單為例
  • TypeScript进阶(二)深入理解装饰器
  • 书生·浦语第三次作业
  • GPT实战系列-LangChain + ChatGLM3构建天气查询助手
  • LeetCode 2696.删除子串后的字符串最小长度:栈
  • Xcode15 升级问题记录
  • List、Set、Map有什么区别?
  • centOS系统yum安装和卸载mongodb
  • 2023年12月 C/C++(一级)真题解析#中国电子学会#全国青少年软件编程等级考试
  • Python爬虫---Scrapy项目的创建及运行
  • PyTorch: torch.nn 子模块及其在循环神经网络中的应用
  • 【QT】自定义代理类
  • 线程休眠、线程让步、线程优先级相关内容学习笔记
  • paddle指定运行gpu
  • Java异常及网络编程
  • 通过 Elastic Stack 充分利用电信领域生成式 AI 的力量
  • Redis:原理速成+项目实战——Redis实战8(基于Redis的分布式锁及优化)
  • 江山易改本性难移之ZYNQ SDK QSPI固化bug及其解决方法
  • 系列三十六、注解版Spring、SpringMVC配置文件
  • 爬虫你需要知道的:什么是http请求
  • MCU FT61F14x入门
  • 星火大模型——多模态API调用(图像+文本)