SpringBoot项目打jar包报错的问题

本文介绍了在SpringBoot项目打包时遇到的jar包报错问题,错误原因是缺少可执行方法。通过在test包下添加测试类并包含一个测试方法,成功解决了打包问题。对于为何必须这样做,文中并未详细解释,期待了解的读者分享。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题是:最近在一次SpringBoot项目打包时发现,打jar包时报错,报错的信息如下:

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building wisdomeyeapi0114 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ wisdomeyeapi0114 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ wisdomeyeapi0114 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ wisdomeyeapi0114 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\xxx\xxx\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ wisdomeyeapi0114 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\xxx\xxx\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ wisdomeyeapi0114 ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.xxx.xxx.WisdomeyeapiApplicationTests
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.299 s <<< FAILURE! - in com.xxx.xxx.WisdomeyeapiApplicationTests
[ERROR] initializationError(com.xxx.xxx.WisdomeyeapiApplicationTests)  Time elapsed: 0.008 s  <<< ERROR!
java.lang.Exception: No runnable methods

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   WisdomeyeapiApplicationTests.initializationError ?  No runnable methods
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.090 s
[INFO] Finished at: 2020-02-12T17:57:55+08:00
[INFO] Final Memory: 38M/292M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project wisdomeyeapi0114: There are test failures.
[ERROR] 

 看了错误信息后才知道最总要的是这句话,随后便查找原因。

 然后就去项目test包下的类中查看是这样的,报错原因就是没有可执行的方法

@RunWith(SpringRunner.class)
@SpringBootTest
public class XXXApplicationTests {




}

 解决办法:在test包下的类中添加一个测试方法,就可以了如下这样:  打包成功!

@RunWith(SpringRunner.class)
@SpringBootTest
public class XXXApplicationTests {
    @Test
    public void contextLoads() {
    }
}

至于为什么会这样,由于时间原因并不知道,希望有知道的大佬帮忙补充,感激不尽。

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值