1、 Problem description
1.1 development environment configuration
pom.xml
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--Be sure to match the springboot version number, because the new version of springboot no longer sets the dependencies of this plugin-->
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
1.2 error
[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]
II. Solution
2.1 Remove repackage
and use mainclass
instead
Configure in the top-level parent project pom.xml
<properties>
<! --needs to be overridden by subclasses to resolve multiple main methods-->
<mainClass>com.taco.springcloud.Application</mainClass>
</properties>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--Be sure to match the springboot version number, because the new version of springboot no longer sets the dependencies of this plugin-->
<version>${spring-boot.version}</version>
<configuration>
<mainClass>${mainClass}</mainClass>
</configuration>
</plugin>
Override the mainclass
attribute in POM. XML
projects that need to be deployed as web projects
<properties>
<mainClass>com.taco.springcloud.TacoConfigServerApplication</mainClass>
</properties>
In this way, even if there are other main methods in the dependent package, no error will be reported