简体   繁体   中英

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.

Currently, under src/main/resources, I have several application.properties files. Such as:

  • application properties
  • application-local.properties
  • application-production.properties
  • application-integration.prorperties

And under the src/test/resources, no properties file.

When I run maven, maven will trigger some unit and integration tests. 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. And currently, with the file under src/main/resources, everything is fine.

I just tried moving the file to src/test/resources, and the integration tests could not find any property, as if the file disappeared.

What is the proper way to tell Springboot to run integration tests with a application-integration.properties under src/test/resrouces please?

Thank you

You can use the below configuration for the Integration tests

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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