Java 弹簧靴从战争走向战争
我试图使用SpringBoot2.0.2从war迁移到jar,但在使用failsafe进行maven测试时遇到了问题 我看到两种错误:Java 弹簧靴从战争走向战争,java,spring,maven,spring-boot,maven-failsafe-plugin,Java,Spring,Maven,Spring Boot,Maven Failsafe Plugin,我试图使用SpringBoot2.0.2从war迁移到jar,但在使用failsafe进行maven测试时遇到了问题 我看到两种错误: 找不到@SpringBootConfiguration,您需要使用@ContextConfiguration或@SpringBootTest java.lang.NoClassDefFoundError列出了我的一个bean类 当我在IntelliJ中运行这些测试时,一切正常,但在maven中失败。 同时,当我回到构建战争而不是jar时,一切都正常 从war到j
找不到@SpringBootConfiguration,您需要使用@ContextConfiguration或@SpringBootTest
java.lang.NoClassDefFoundError
列出了我的一个bean类重新打包的目标:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>${spring.boot.skip}</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
</dependencies>
</plugin>
我的测试类带有以下注释:
@EnableConfigurationProperties
@TestExecutionListeners(listeners = {
DirtiesContextTestExecutionListener.class,
DirtiesContextBeforeModesTestExecutionListener.class,
ServletTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class,
TransactionalTestExecutionListener.class,
MockitoTestExecutionListener.class
})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Import(TestConfiguration.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
另一个难题,当我使用
mvn clean test-compile failsafe:integration-test
它们都能工作,所以只有在mvn clean install的情况下才会失败,为什么?好的,问题是我使用的是failsafe 2.19.1,这个版本自Spring boot 1.4.x以来就出现了问题:
解决方案是将故障保护降级到2.18,升级(但随后会出现另一组问题)或添加
exec
对于spring boot maven插件的配置部分,在我的例子中是:
org.springframework.boot
springbootmaven插件
${spring.boot.skip}
执行官
构建信息
org.springframework
弹簧负载
1.2.6.1发布
如果是JUnit失败了,您有@SpringBootTest吗?我没有看到您的JUnit代码。1)默认情况下启用了重新打包目标。为什么要添加它?为什么要添加带有战争变化的弹簧?2) 主类如何编译?您在configure()
方法中指定了@Override
,但您的类扩展了对象
!如果你想得到相关的提示/答案,请尽量说得更清楚、更准确。是的,所有SpringBootTests都失败了。不确定spring boot的war和jar有什么不同。以及为什么它们在IDE中工作而不是在maven中。@davidxxx我从war案例中复制,现在更新
mvn clean test-compile failsafe:integration-test
<classifier>exec</classifier>