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

后端 未结 11 1876
旧巷少年郎
旧巷少年郎 2020-12-13 00:06

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

相关标签:
11条回答
  • 2020-12-13 00:48

    To disambiguate the entry point of a spring boot application, you can add the following directive to your Gradle build file

    springBoot {
        mainClassName = 'your.org.bla.TestKt'
    }
    
    0 讨论(0)
  • 2020-12-13 00:54

    or simply hard code the main class in plugin configuration.

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <mainClass>your.main.class.MainClass</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
    0 讨论(0)
  • 2020-12-13 00:54

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

    0 讨论(0)
  • 2020-12-13 00:55

    I was building a spring boot library project, so I don't need a main starter class, so I faced the same issue while building the project with maven, so I removed the maven plugin to compile successfully

    <!--
        <build>
          <plugins>
            <plugin>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
          </plugins>
        </build>
    -->
    

    For a more detailed example. find it here https://spring.io/guides/gs/multi-module/

    0 讨论(0)
  • 2020-12-13 01:00

    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>
    
    0 讨论(0)
提交回复
热议问题