【问题标题】:org.springframework.boot:spring-boot-maven-plugin:1.5.10.RELEASE:repackage failed: Unable t o find main classorg.springframework.boot:spring-boot-maven-plugin:1.5.10.RELEASE:repackage failed: Unable t o find main class
【发布时间】:2023-03-05 19:38:02
【问题描述】:

我有以下项目结构:

parent pom
   |
   - Core module - pom
   - Dist - pom
   - Integration test - pom

Spring boot 主类在核心模块中。集成测试将进入集成测试文件夹。

我正在尝试使用 spring-boot-maven-plugin 进行集成测试。 我在集成测试模块中完成了以下 pom 配置。 start-class 属性在父 pom 中设置:

         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>${start-class}</mainClass>
                <layout>JAR</layout>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
                <execution>
                    <id>pre-integration-test</id>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>post-integration-test</id>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

但是我在父 pom 上的 mvn clean install 上收到以下错误:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.10.RELEASE:start (pre-integration-test) on pro

ject: Spring 应用程序在配置的超时之前没有启动(30000ms -> [Help 1] [错误]

问题:

  1. 这种项目结构是组织集成的最佳方式吗 测试?
  2. 如何以及在何处将主类的路径提供给 spring-boot-maven-plugin 正确吗?即使我给它也不起作用 它在集成模块或父 pom 中,即使给出了 您通常会执行的相对路径(例如 ../core-module/)
  3. 测试类本身上的 maven-failsafe-plugin 和 spring 注释似乎足以运行集成测试。那么首先集成测试和spring boot maven插件之间有什么关系吗?除了打包成可执行文件之外,spring boot maven插件还需要什么。我有这种困惑,因为它的目标是开始预集成测试和集成后测试,但我不明白为什么需要它。

PS:我检查了几个具有类似问题的问题,但没有人回答我针对给定项目结构提出的问题。

【问题讨论】:

    标签: maven spring-boot spring-boot-maven-plugin


    【解决方案1】:

    我刚刚遇到了和你一样的错误(repackage failed: Unable t o find main class) 试图将一些 Spring 代码推广到一个常见的 Spring Boot 项目中。 事实证明这是不可能的,因为 Spring boot 项目需要一个带有 main 方法的类。

    我使用直接依赖于我需要的 spring 框架模块来解决我的问题,也许你可以在你的集成测试项目中这样做。

    但是,我不知道您要在单独的项目中运行什么样的测试,但是有关核心模块的测试必须在核心模块本身中,使用 Spring 测试,而不是在单独的项目中。 (在需要的地方使用模拟)。

    希望这会有所帮助。

    【讨论】:

    • 完整的项目是一个微服务。我正在尝试在单独的模块中为整个微服务作为一个组件运行集成测试。关于核心模块的测试,即junit测试仅在核心模块中,但不能保留集成测试,因为未来可能会有更多模块而不是核心(或核心本身进一步分解为更多模块)和集成测试用于将整个微服务作为一个单元进行测试。
    • “我使用直接依赖于我需要的 spring 框架模块来解决我的问题,也许你可以在集成测试项目中做到这一点”是什么意思?
    • 好的,所以补充一下,我明白了,您不需要将集成测试模块编译到 jar 中,因为它只包含用于测试整个系统的 junit 测试。因此,只需从您的 pom 中删除 Maven 插件 spring-boot-maven-plugin,然后直接或在您的 CI 上运行测试
    猜你喜欢
    • 2014-06-22
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 1970-01-01
    • 2019-05-30
    • 2021-07-08
    • 2023-03-17
    • 2021-10-30
    相关资源
    最近更新 更多