小编典典

Spring Boot无法运行maven-surefire-plugin ClassNotFoundExceptionorg.apache.maven.surefire.booter.ForkedBooter

spring-boot

运行 Spring Boot 2.0.2的Maven(3.5.2)构建(由具有Web依赖项的Web初始化程序生成)会执行 maven-
surefire-plugin
失败,只是说:

错误:找不到或加载主类org.apache.maven.surefire.booter.ForkedBooter

造成原因:java.lang。 ClassNotFoundException
:org.apache.maven.surefire.booter。 叉车工

为什么会这样呢?引导+ surefire集成=错误有问题吗?

作为参考,似乎相关的依赖项是:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
    <relativePath/>
</parent>
...
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
</dependency>
...
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

阅读 1051

收藏
2020-05-30

共1个答案

小编典典

该问题的解决方法是重写Spring Boot的maven-surefire- plugin定义并将其设置useSystemClassLoaderfalse。阅读Surefire文档以获取更多详细信息

<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <useSystemClassLoader>false</useSystemClassLoader>
            </configuration>
        </plugin>
    </plugins>
</build>
2020-05-30