Spring Boot Which main class to start

摘要: If Spring Boot project contains multiple main classes, Spring Boot will fail to start or packag for deployment.

If Spring Boot project contains multiple main classes, Spring Boot will fail to start or packag for deployment.

Terminal
$ mvn package 
#or
$ mvn spring-boot:run
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:run (default-cli) 
Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:run failed: 
Unable to find a single main class from the following candidates 
 [com.mkyong.Test, com.mkyong.SpringBootWebApplication] -> [Help 1]

Maven example

1.1 Define single main class via start-class properties

pom.xml
  <properties>
      <!-- The main class to start by executing java -jar -->
      <start-class>com.mkyong.SpringBootWebApplication</start-class>
  </properties>

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

pom.xml
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.mkyong.SpringBootWebApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

References

  1. Spring Boot – The executable jar format
  2. Spring Boot Maven Plugin – Usage

上一篇: Intellij IDEA – Spring boot reload static file is not working
下一篇: JExcel API Reading and Writing Excel file in Java
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号