从eclipse + gradle运行时,Spring Boot错误地加载测试配置 [英] Spring Boot incorrectly loads test configuration when running from eclipse+gradle
问题描述
当我将Spring Boot应用程序从Eclipse(STS)运行为Java应用程序或Spring Boot App时,该应用程序将失败,因为它尝试从 test classpath 加载配置(@Configuration)。
When I run Spring Boot application from Eclipse (STS) as 'Java Application' or as 'Spring Boot App' the app fails because it tries to load configurations (@Configuration) from test classpath.
事实是,它适用于基于maven的构建,但不适用于毕业生。
The thing is that it works for maven based builds correctly, but not for gradle.
唯一的解决方法我看到的是将测试包重命名为别的东西以将其从类路径扫描中隐藏。
The only workaround I see is to rename test package to something else to hide it from classpath scanning.
总体来说,问题是 - 如何使其正常工作?我假设SpringToolSuite团队每天遇到这个问题,或者我做错了事情。
Overall the question is - how to make it work properly? I'd assume that SpringToolSuite team encounters this problem on a daily basis or I do something incorrectly.
这是一个测试项目,当导入为maven时工作,但在导入时失败作为毕业生: https://github.com/mabn/spring-boot-integration-test
Here's a test project which works when imported as maven, but fails when imported as gradle: https://github.com/mabn/spring-boot-integration-test
- 这是一个年龄段STS问题 - 是否仍然相关?
- 另一个标记为已解决的人
- 关于maven项目的类似问题
- Here's a year-old STS issue - is it still relevant?
- Here's another one marked as resolved
- Similar question about maven projects
我正在使用STS 3.7.1
I'm using STS 3.7.1
推荐答案
事实是,它适用于基于maven的构建,但不适用于毕业生。
The thing is that it works for maven based builds correctly, but not for gradle.
是的,不幸的是就是这样Gradle根本不配置eclipse的运行时类路径。这就是Gradle自己的新BuildShip eclipse插件的情况。
Yes, unfortunately that is the case. Gradle doesn't deal properly with configuring eclipse's runtime classpath at all. This is even the case with Gradle's own new BuildShip eclipse plugin.
看到我最近提出的这个问题:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=482315
See this issue I recently raised: https://bugs.eclipse.org/bugs/show_bug.cgi?id=482315
你发现的解决的bug确实解决了,但它只关心maven / m2e的情况,这实际上是可修复的(m2e对Run As >> Java Project这样做是正确的,我们采用了类似于Run As >> Spring Boot App的修复程序)。但是,该修复程序是特定于maven的,因为毕业案例并不能真正解决,直到此Gradle工具api问题单解决:
The resolved bug you found is indeed resolved, but it only concerned the maven/m2e case, which is in fact fixable (m2e does this correcty for "Run As >> Java Project" and we adopted a similar fix for "Run As >> Spring Boot App"). However, that fix is maven-specific as the gradle case is not really fixable until this Gradle tooling-api issue ticket is resolved:
https://issues.gradle.org/browse/GRADLE-1777
这篇关于从eclipse + gradle运行时,Spring Boot错误地加载测试配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!