Table of Contents
When Spring boot application contains multiple main class at that time exception will be thrown at time of compilation because spring boot will get confused from which main should start application, If application contains single main class there nothing to worries but if multiple main class then we should provide explicitly at time of compilation from which class application should start. Here is different ways to provide main class in spring boot application:
Exception: Spring boot Unable to find a single main class from the following candidates
While compiling spring boot application and throwing exception when application have more then one class with
public static void main(String args) methods.
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.4.RELEASE:repackage (default) on project spring-boot-example: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.4.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.javadeveloperzone.SpringBootConfig, com.javadeveloperzone.SpringBootConfig1] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [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
Solution 1 – mainClass in spring boot maven plugin:
spring-boot-maven-plugin's a configuration as like:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.javadeveloperzone.SpringBootConfig</mainClass> </configuration> </plugin> </plugins> </build>
Solution 2: add start-class in maven properties
pom.xml write bellow configuration in which <start-class> contains name of the class file which will be consider as main class of spring boot application.
<properties> <start-class>com.javadeveloperzone.SpringBootConfig</start-class> </properties>