1

We would like to merge src/main/resources/application.properties with additional default properties when running tests which in turn should be included by other (test) properties files activated via specific profiles in our Spring Boot application.

Up until Spring Boot 2.4 this worked quite well by having all common test properties in src/test/resources/application-default.properties to keep things DRY. Those were then automatically merged with the ones from src/main/resources/application.properties by Spring [1]. This allowed us to have our own set of default properties without requiring tests to specify an @ActiveProfiles("default").

Other (test) profiles could then have their own application-<profile>.properties with spring.profiles.include=default and then further extend the defaults.

With Spring Boot 2.4 I'm struggling with the new "rules":

  • I can no longer load application-default.properties from application-<profile>.properties since spring.profiles.include is no longer allowed in non profile-specific documents [2].

  • I don't want to introduce a src/test/resources/application.properties since I don't want to repeat everything from src/main/resources/application.properties. Also I don't want to load any activate any test-related profiles in the app's properties.

It looks like one solution could be to explicitly add spring.profiles.include=default to src/main/resources/application.properties to force the application to include the properties file with default properties which will work as before when it comes to running the actual application but consider src/test/resources/application-default.properties when running the tests.

Is this the way to go or are there smarter solutions to tackle this problem and still keep the properties free of redundancies?

Thomas W.
  • 51
  • 6

1 Answers1

0

spring.profiles.active=dev

add this config in application.properties file

enter image description here

  • 3
    Activating a profile is just one step to load the correct properties. However in my question I'm asking about correct properties file structuring for test to merge with `src/main/resources/application.properties` and enable property file inclusion with Spring Boot 2.4+. – Thomas W. Dec 29 '21 at 11:39