I\'ve generated a Spring Boot web application using Spring Initializer, embedded Tomcat, Thymeleaf template engine.Technologies used: Spring Boot 1.4.2.RELEASE, Spring 4.3.4
If you have a Spring Boot Application generally there is only one main class that has @SpringBootApplication
, If you add another main
method in the application some where , the gradle build process gets confused . So add the following at the root level of your build.gradle
file
apply plugin: 'application'
mainClassName = 'packageNameAfter.srcMainJavaFolder.YourClassName'
I had the same error. I had renamed my Application class containing main from foo.java to bar.java, cleaned and updated. So I only ever had one main.
The error went away when I deleted the old generated class, foo.class under the target folder.
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage (default) on project book: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.tdk.BookApplication, com.tdk.BookApplicationWar]
One possible reason to getting following error is more than one main methods in your code, Spring boot allow only one main method across all class in same project.
From the command line you can use
... -Dstart-class=com.your.package.application.BookApplication
If you have more than one main class, you need to explicitly configure the main class in each profile:
<profiles>
<profile>
<id>profile1</id>
<properties>
<spring.boot.mainclass>com.SomeClass</spring.boot.mainclass>
</properties>
</profile>
<profile>
<id>profile2</id>
<properties>
<spring.boot.mainclass>com.SomeOtherClass</spring.boot.mainclass>
</properties>
</profile>
</profiles>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.2.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>${spring.boot.mainclass}</mainClass>
</configuration>
</execution>
</executions>
...
</plugin>
See spring-boot:repackage
Check your application if you have multiple classes with public static void main(String[] args)
. Remove the one that you do not need. Specially if you generate the project with https://start.spring.io/
it comes with a class with main method in it.
If you do need all of the classes with main method just explicitly mention which one would to be boos-trapped up on application start up by mentioning it in the pom.