异构微服务远程调用如何打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}

相关推荐

  1. 服务远程调用如何jar

    2024-01-10 06:20:01       39 阅读
  2. <span style='color:red;'>打</span><span style='color:red;'>jar</span><span style='color:red;'>包</span>

    jar

    2024-01-10 06:20:01      12 阅读
  3. SpringBoot jar如何获取jarResouces下的文件

    2024-01-10 06:20:01       25 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-10 06:20:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-10 06:20:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-10 06:20:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-10 06:20:01       20 阅读

热门阅读

  1. Linux和windows进程同步与线程同步那些事儿(一)

    2024-01-10 06:20:01       28 阅读
  2. Ubuntu and Mac OSX之间传输文件(共享文件夹方法)

    2024-01-10 06:20:01       41 阅读
  3. Python数据类型转换

    2024-01-10 06:20:01       36 阅读
  4. #{}和${}的区别?

    2024-01-10 06:20:01       23 阅读
  5. 离线安装docker和docker-compose

    2024-01-10 06:20:01       40 阅读
  6. 深度学习中Epoch和Batch Size的关系

    2024-01-10 06:20:01       35 阅读
  7. 树莓派Debian系统中如何用mDNS广播自己的ip地址

    2024-01-10 06:20:01       34 阅读
  8. [力扣 Hot100]Day1 两数之和

    2024-01-10 06:20:01       41 阅读