SpringBoot: Unable to find a single main class from the following candidates

Solution 1:

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

Solution 2:

Define single main class via start-class property

<properties>
      <start-class>com.may.Application</start-class>
</properties>

Alternatively, define the main class in the spring-boot-maven-plugin

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>com.may.Application</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

Or via profiles

<profiles>
        <profile>
            <id>profile1</id>
            <properties>
                <spring.boot.mainclass>com.may.Application1</spring.boot.mainclass>
            </properties>
        </profile>
        <profile>
            <id>profile2</id>
            <properties>
                <spring.boot.mainclass>com.may.Application2</spring.boot.mainclass>
            </properties>
        </profile>
</profiles>

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <mainClass>${spring.boot.mainclass}</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Solution 3:

Sometimes this error is given when you do mvn install without doing mvn clean.