您的位置:首页 > 编程语言 > Java开发

异常处理(六)--------SpringBoot+Maven项目运行异常:Unable to find a single main class from the following candidat

2020-03-24 12:15 701 查看

异常详情

[code]Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:run (default-cli) on project ******:
Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:run failed:
Unable to find a single main class from the following candidates [utils.UniqueStringUtils, utils.UniqueStringUtil, utils.DateUtil, utils.Base64, cn.yzstu.*]

场景描述

今天在做一个小功能的时候,新开了一个项目做测试,期间copy了一些工具类到新项目中,一切准备就绪,命令:mvn spring-boot:run *,运行项目,出现以上报错。

解决办法

异常的主要信息在最后一行:Unable to find a single main class from the following candidates,翻译过来就是“在以下候选中找到不止一个main类”,去报错信息中给出的类中查找

在这个类里有我以前测试留下来的main方法,注释掉,同样的去其他几个类里面。找到main方法注释掉(针对新人:主main需要留下)。

问题解决

完事儿后可以正常运行。

总结

maven在执行打包的时候会查找项目中的main方法,并设置为Spring boot 生成jar包的启动入口,但此时有多个main方法,maven插件就无所适从了。因此出现此异常。

因此,注释掉其他无用的main方法即可解决此问题。

  • 点赞 1
  • 收藏
  • 分享
  • 文章举报
Baldwin_KeepMind 发布了51 篇原创文章 · 获赞 277 · 访问量 14万+ 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐