Spring Boot多模块maven项目重新打包失败

Jam*_*mes 6 java spring-mvc multi-module spring-boot spring-boot-maven-plugin

我目前正在学习 John Thompson 的 Spring 框架初学者到大师课程。我按照他的一步步程序在 Spring Boot 上为 Spring Pet Clinic 创建多模块 Maven 项目。当我单击根模块上的包时,它显示重新打包失败,无法找到主类。

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </execution>
        </executions>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

[错误] 无法在项目 pet-clinic-data 上执行目标 org.springframework.boot:spring-boot-maven-plugin:2.1.6.RELEASE:repackage(重新打包):目标 org.springframework.boot:spring 的执行重新打包-boot-maven-plugin:2.1.6.RELEASE:重新打包失败:无法找到主类 -> [帮助 1]

小智 8

消除

 <configuration>
       <skip>true</skip>
   </configuration>
Run Code Online (Sandbox Code Playgroud)

并添加“spring-boot.repackage.skip”属性,如下所示:

<artifactId>pet-clinic-data</artifactId>
    <properties>
        <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
    </properties>
Run Code Online (Sandbox Code Playgroud)


Yon*_*oss 6

您正在使用 spring-boot-maven-plugin:2.1.6.RELEASE。

从 Spring-Boot 2 开始,您不再需要 Spring Boot 插件。

您可以在声明模块的工件 ID 后使用以下代码。

<artifactId>pet-clinic-data</artifactId>
<properties>
    <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>
Run Code Online (Sandbox Code Playgroud)


fed*_*dup 6

spring-boot-maven-plugin 应该只位于包含主类的模块的 pom.xml 中。看起来您将此插件放在一个简单的 jar 模块上(或由其继承),主模块将使用该模块作为依赖项。

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

主类使用@SpringBootApplication注解


Ala*_*reb 0

错误本身就说明了一切。执行者找不到你的主类。它与你的pom.xml无关。但与您用来构建和运行 Spring Boot 项目的环境有关。

如果您使用的是 IntelliJ,请转到Run/Debug configurationAdd configuration在屏幕截图上,在您的情况下可能是其他内容)并确保您的主类退出。然后点击你的班次两次并输入Invalidate Caches/Restart并执行这两项操作。然后它应该按预期工作。

智能配置