SpringBoot学习之一 Unable to find a single main class from the following candidates

在启动SpringBoot项目是报错

Unable to find a single main class from the following candidates [boot.myboot.SampleController, boot.myboot.App]

意思 是从这两个类中找不到要执行那个main方法

执行spring-boot:run -X打印出Debug日志

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.7.RELEASE:run (default-cli) on project myboot: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:1.4.7.RELEASE:run failed: Unable to find a single main class from the following candidates [boot.myboot.SampleController, boot.myboot.App] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.7.RELEASE:run (default-cli) on project myboot: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:1.4.7.RELEASE:run failed: Unable to find a single main class from the following candidates [boot.myboot.SampleController, boot.myboot.App]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:1.4.7.RELEASE:run failed: Unable to find a single main class from the following candidates [boot.myboot.SampleController, boot.myboot.App]
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 20 more
Caused by: java.lang.IllegalStateException: Unable to find a single main class from the following candidates [boot.myboot.SampleController, boot.myboot.App]
    at org.springframework.boot.loader.tools.MainClassFinder$MainClassesCallback.getMainClass(MainClassFinder.java:348)
    at org.springframework.boot.loader.tools.MainClassFinder.findSingleMainClass(MainClassFinder.java:99)
    at org.springframework.boot.maven.AbstractRunMojo.getStartClass(AbstractRunMojo.java:360)
    at org.springframework.boot.maven.AbstractRunMojo.execute(AbstractRunMojo.java:170)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    ... 21 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

错误原因是因为:在这两个类中都包含main方法,所以项目在运行时不知大概执行那个main方法开始项目

 

解决方法:两个类中的main方法只保留一个

点赞