繁体   English   中英

Springboot - application-integration.properties 在 src/main/resources 下工作,但不在 src/test/resources 下工作

[英]Springboot - application-integration.properties working under src/main/resources, but not under src/test/resources

请关于适用于 Springboot 的 Spring 配置文件(集成)的小问题。

目前,在 src/main/resources 下,我有几个 application.properties 文件。 如:

  • 应用程序属性
  • 应用程序-local.properties
  • 应用程序生产属性
  • 应用程序集成.properties

并且在 src/test/resources 下,没有属性文件。

当我运行 maven 时,maven 会触发一些单元和集成测试。 单元测试不需要任何特定的配置文件(属性在单元测试中设置,无论如何,这不是问题)。

集成测试,他们需要 application-integration.properties。 目前,使用 src/main/resources 下的文件,一切都很好。

我刚刚尝试将文件移动到 src/test/resources,集成测试找不到任何属性,好像文件消失了一样。

请告诉 Springboot 使用 src/test/resrouces 下的 application-integration.properties 运行集成测试的正确方法是什么?

谢谢

您可以将以下配置用于集成测试

@TestPropertySource(locations = "classpath:application-integration.properties")
@ActiveProfiles("integration")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM