您现在的位置是:首页 > SpringBoot启动报错Unable to find a suitable main class

SpringBoot启动报错Unable to find a suitable main class

默认 2023-01-10 09:27 1722人围观 来源:原创
 
简介Unable to find a suitable main class, please add a 'mainClass' property

在启动一个spring-boot多模块项目时始终报错:Unable to find a suitable main class, please add a 'mainClass' property

试了如增加mainClass配置无效,最终定位是因为父pom里面存在:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.1.RELEASE</version>
</parent>

而spring-boot-starter-parent中包含spring-boot-maven-plugin,而父模块并没有主类入口所以需要跳过:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <skip>true</skip>
    </configuration>
</plugin>

需要注意的是子模块如果有引入spring-boot-maven-plugin,需要将skip设置为false,否则会出现全部模块编译成功,但是没有服务启动的情况。

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <skip>false</skip>
    </configuration>
</plugin>

 

 

 

 

我的博客即将同步至腾讯云开发者社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=3cn0udci9ym88

文章评论