一、问题描述

1.1 开发环境配置

  1. pom.xml
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--一定要对上springboot版本号,因为新版springboot不再设置这个插件的依赖-->
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>

1.2 错误异常

​[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.17.RELEASE:repackage (default) on project taco-cloud-eureka-server: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.1.17.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.xxx.xxx.Application, com.xxx.xxx.Application]​

二、解决方法

2.1 去掉​​repackage​​​,使用​​mainclass​​替代

  1. 在顶级父工程​​pom.xml​​中配置
<properties>
<!--需要子类覆盖该属性,解决有多个main方法-->
<mainClass>com.taco.springcloud.Application</mainClass>
</properties>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--一定要对上springboot版本号,因为新版springboot不再设置这个插件的依赖-->
<version>${spring-boot.version}</version>
<configuration>
<mainClass>${mainClass}</mainClass>
</configuration>
</plugin>
  1. 在需要部署为web工程的项目​​pom.xml​​​中覆盖​​mainClass​​属性
<properties>
<mainClass>com.taco.springcloud.TacoConfigServerApplication</mainClass>
</properties>

这样即使依赖包中的有其他main方法也不会报错