异常处理(六)--------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
- 收藏
- 分享
- 文章举报
相关文章推荐
- Maven使用package打包Spring Boot时出现:Unable to find a single main class from the following candidates的问题解决
- Springboot repackage failed: Unable to find a single main class from the following candidates
- SpringBoot学习之一 Unable to find a single main class from the following candidates
- Unable to find a single main class from the following candidates
- mvn clean package 报错Unable to find a single main class from the following candidates
- Unable to find a single main class from the following candidates
- 解决Unable to find a single main class from the following candidates [xxx,xxx]
- Unable to find a single main class from the following candidates
- Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE:repackage failed: Unable to find main class
- maven打包报错:spring-boot-maven-plugin:2.0.1.RELEASE:repackage failed: Unable to find main class
- spring boot打包时Unable to find a single main class的解决方法
- spring boot maven Unable to find main class
- Spring Boot应用的Unable to find main class异常详解
- [springboot] spring-boot:run 命令启动报错,Unable to find a suitable main class, please add a 'mainClass'
- Caused by: java.lang.IllegalStateException: Unable to find a single main class from问题解决
- 在maven项目中使用apache cxf中遇到异常 java.lang.ClassCastException: org.springframework.web.filter.CharacterEncodingFilter cannot be cast to javax.servlet.Filter
- Spring Boot之mvnw的启动错误Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain
- 运行maven项目出现:Error: Could not find or load main class com.xxx.xxxx
- unable to find javac compiler;com.sun.tools.javac.Mainisnotontheclasspath的问题的解决
- unable to find javac compiler;com.sun.tools.javac.Mainisnotontheclasspath的问题的解决