核心报错点
Caused by: java.lang.NoClassDefFoundError: com/lop/open/api/sdk/request/DomainAbstractRequest
部分pom文件
<dependency>
<groupId>com.lop</groupId>
<artifactId>open-api-sdk-open</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/lop_opensdk_support_1028.jar</systemPath>
</dependency>
<dependency>
<groupId>com.lop</groupId>
<artifactId>open-api-sdk-trans</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/TransferCenterService_v6_20250611163859.jar</systemPath>
</dependency>
<dependency>
<groupId>com.lop</groupId>
<artifactId>open-api-sdk-common</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/IntegratedLogistics_v1_20241015154119.jar</systemPath>
</dependency>
原因
system 范围的依赖问题:
使用了 <scope>system</scope>
,并通过 systemPath 指定了一个本地路径的 JAR 文件。
system 范围的依赖不会被打包到最终的 JAR 文件中。这意味着在本地运行时,IDEA 能找到该依赖,但在打包后运行时,Spring Boot 无法加载该依赖。
本地路径依赖的局限性:
systemPath 是一个绝对路径或相对路径,依赖于项目的目录结构。
在打包后运行时,systemPath 指定的 JAR 文件可能无法被正确加载,因为它不会被包含在最终的 JAR 文件中。
Spring Boot 打包机制:
Spring Boot 的打包机制(例如 spring-boot-maven-plugin)会将所有 compile 和 runtime 范围的依赖打包到最终的可执行 JAR 中。
但 system 范围的依赖不会被包含在内
解决
在build时 将system指定进去
<includeSystemScope>true</includeSystemScope>
附pom文件
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.4.RELEASE</version>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>