使用 maven-failsafe-plugin spring-boot 1.4 进行集成测试时出现 TypeNotPresentExceptionProxy 错误

TypeNotPresentExceptionProxy error at integration-test with maven-failsafe-plugin spring-boot 1.4

我得到 ArrayStoreException: TypeNotPresentExceptionProxy 当 运行ning integration-test with maven-failsafe-plugin 和 spring-boot 1.4.

如果你 运行 joinfaces-example

你会看到这个错误

mvn -补丁集成测试全新安装

我意识到如果我在 pre-integration-test 阶段将 spring-boot-maven-plugin 更改为 运行 则不会发生错误而不是 package one.

此外,当我将 spring boot 升级到 1.4 时出现此错误。如果我将 jsf-spring-boot-parent 版本更改为使用 spring 引导 1.3 版本的 2.0.0,则不会发生错误。

我实际上在 Spring Boot 1.4 release notes 中找到了答案,简短的回答是 maven-failsafe-plugin 与 Spring Boot 1.4 的新可执行布局不兼容。完整解释如下:

As of Failsafe 2.19, target/classes is no longer on the classpath and the project’s built jar is used instead. The plugin won’t be able to find your classes due to the change in the executable jar layout. There are two ways to work around this issue:

  • Downgrade to 2.18.1 so that you use target/classes instead

  • Configure the spring-boot-maven-plugin to use a classifier for the repackage goal. That way, the original jar will be available and used by the plugin. For example :

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <classifier>exec</classifier>
    </configuration> 
</plugin>

此处记录了替代方法:https://github.com/spring-projects/spring-boot/issues/6254

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <!--
        Make failsafe and spring-boot repackage play nice together,
        see https://github.com/spring-projects/spring-boot/issues/6254
    -->
    <configuration>
        <classesDirectory>${project.build.outputDirectory}</classesDirectory>
    </configuration>
</plugin>

这对我来说效果更好,因为当我使用 "exec" 解决方案时,Spring 在启动容器时找不到我的配置文件。我想这可能可以通过添加一些进一步的配置参数来解决,但是这个解决方案对我有效"out of the box"。