如何告诉Spring Boot要用于可执行jar的主类?

Execution default of goal 
org.springframework.boot:spring-boot-maven-plugin:1.0.1.RELEASE:repackage 
failed: 
Unable to find a single main class from the following candidates

我的项目有多个具有方法的类。我如何告诉Spring Boot Maven插件它应该使用哪些类作为主类?main


答案 1

在你的 pom 中添加你的起始类:

<properties>
    <!-- The main class to start by executing java -jar -->
    <start-class>com.mycorp.starter.HelloWorldApplication</start-class>
</properties>

<build>
<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>             
        <configuration>    
            <mainClass>com.mycorp.starter.HelloWorldApplication</mainClass>
        </configuration>
    </plugin>
</plugins>
</build>

答案 2

对于那些使用Gradle(而不是Maven)的人:

springBoot {
    mainClass = "com.example.Main"
}

推荐