【问题标题】:Spring Boot incorrectly loads test configuration when running from eclipse+gradle从 eclipse+gradle 运行时 Spring Boot 错误加载测试配置
【发布时间】:2016-02-22 09:13:08
【问题描述】:

当我从 Eclipse (STS) 将 Spring Boot 应用程序作为“Java 应用程序”或“Spring Boot App”运行时,该应用程序失败,因为它尝试从 test classpath 加载配置 (@Configuration)。

问题是它适用于基于 maven 的构建,但不适用于 gradle。

我看到的唯一解决方法是将测试包重命名为其他名称以将其隐藏在类路径扫描中。

总的来说,问题是——如何让它正常工作?我假设 SpringToolSuite 团队每天都会遇到这个问题,或者我做错了什么。

这是一个测试项目,在导入为 maven 时有效,但在导入为 gradle 时失败:https://github.com/mabn/spring-boot-integration-test

我使用的是 STS 3.7.1

【问题讨论】:

    标签: eclipse gradle spring-boot spring-tool-suite


    【解决方案1】:

    问题是它适用于基于 maven 的构建,但不适用于 gradle。

    是的,不幸的是,情况就是这样。 Gradle 根本无法正确处理配置 eclipse 的运行时类路径。甚至 Gradle 自己的新 BuildShip eclipse 插件也是如此。

    查看我最近提出的这个问题: https://bugs.eclipse.org/bugs/show_bug.cgi?id=482315

    您发现的已解决的错误确实已解决,但它只涉及 maven/m2e 的情况,这实际上是可以修复的(m2e 对“运行方式 >> Java 项目”进行了纠正,我们对“运行”采用了类似的修复作为>> Spring Boot App”)。但是,该修复是特定于 maven 的,因为在解决此 Gradle tooling-api 问题单之前,gradle 案例无法真正修复:

    https://issues.gradle.org/browse/GRADLE-1777

    【讨论】:

    • 回答我自己 - 最简单的解决方案是在测试类路径上注释配置,例如使用@Profile("integration") 并将“integration”添加到测试类的@ActiveProfiles。
    【解决方案2】:

    我不得不为此引入配置文件的分离。 具有所有测试标记 @ActiveProfiles("srv-test")@Profile({"local", "docker"}) 的主要配置

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-03
      • 2021-06-13
      • 2017-02-12
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 2021-10-02
      相关资源
      最近更新 更多