简体   繁体   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

Small question regarding a Spring profile (integration) applied to Springboot please.请关于适用于 Springboot 的 Spring 配置文件(集成)的小问题。

Currently, under src/main/resources, I have several application.properties files.目前,在 src/main/resources 下,我有几个 application.properties 文件。 Such as:如:

  • application properties应用程序属性
  • application-local.properties应用程序-local.properties
  • application-production.properties应用程序生产属性
  • application-integration.prorperties应用程序集成.properties

And under the src/test/resources, no properties file.并且在 src/test/resources 下,没有属性文件。

When I run maven, maven will trigger some unit and integration tests.当我运行 maven 时,maven 会触发一些单元和集成测试。 The unit test does not need any particular profile (properties are set in the unit tests, anyway, it is not the question).单元测试不需要任何特定的配置文件(属性在单元测试中设置,无论如何,这不是问题)。

The integration tests, they need the application-integration.properties.集成测试,他们需要 application-integration.properties。 And currently, with the file under src/main/resources, everything is fine.目前,使用 src/main/resources 下的文件,一切都很好。

I just tried moving the file to src/test/resources, and the integration tests could not find any property, as if the file disappeared.我刚刚尝试将文件移动到 src/test/resources,集成测试找不到任何属性,好像文件消失了一样。

What is the proper way to tell Springboot to run integration tests with a application-integration.properties under src/test/resrouces please?请告诉 Springboot 使用 src/test/resrouces 下的 application-integration.properties 运行集成测试的正确方法是什么?

Thank you谢谢

You can use the below configuration for the Integration tests您可以将以下配置用于集成测试

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

暂无
暂无

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

相关问题 Maven - 如何告诉 Maven 在 src/test/resources 下使用 application-integration.properties 运行集成测试? - Maven - How to tell Maven to run integration tests with application-integration.properties under src/test/resources? 错误原因:SpringBoot 2.0 应用程序中 src/main/resources/config/env/dev2 下的文件的 java.io.FileNotFoundException - Error Caused by: java.io.FileNotFoundException for file under src/main/resources/config/env/dev2 in SpringBoot 2.0 application 应用程序(src / main)运行时,类路径中的src / test / resources中的文件是? - Are files in src/test/resources on classpath while application (src/main) is running? webapp / WEB-INF或src / main / resources下的资源文件? - resource files under webapp/WEB-INF or src/main/resources? 无法访问src / main / resources /下的文件 - Can't get to a file located under src/main/resources/ chrome和firefox webdriver在src / main / resources下找不到? - chrome and firefox webdriver can not be found under src/main/resources? 与Maven远程资源共享/ src / test / resources下的资源 - Sharing resource under /src/test/resources with maven remote resource 让 Eclipse 使用 src/test/resources 而不是 src/main/resources - Make Eclipse use src/test/resources instead of src/main/resources 测试时将使用src / main / resources和src / test / resources目录中的哪个application.yml - Which application.yml that're in src/main/resources and src/test/resources directories will be used when testing Spring xml + JUnit-xml上下文文件在src / test / resources中不起作用,但是在src / main / resources中起作用 - Spring xml + JUnit - xml context file not working in src/test/resources but works in src/main/resources
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM