Search code examples
springspring-bootspring-boot-configuration

Cant find the reason that reverts the behavior of spring.config.location to older Springboot versions


We have a deployment env which use to/uses -spring.config.location=app.properties property to provide the config location. Like mentioned in this post & this one github-br I wasn't aware that for my current springboot version i.e. 2.2.5.RELEASE the properties behavior has changed. As expected we had to use spring.config.additional-location so that it picks the default values from the jar as well.

The problem is however that for another application in the same env which has the same spring boot version i.e. 2.2.5.RELEASE spring.config.location is behaving the old way. So I am still wondering how that is happening for e.g. due to some other dependency which the other app has and our app doesnt?

I don't know what code example to give as I don't know what code is causing the behavior to revert to old version. However here are some differences between the implementations of the 2 apps that I could see:

  1. The other app uses @Value annotations. Our app uses @ConfigurationProperties to load the property values. I tried using it but the config location behavior did not revert.
  2. On some classes they have used @PropertySource(value = "classpath:application.properties")
  3. Other app is relatively older and they have been upgrading the springboot versions if that makes a difference in any way.

These are some the differences I could spot as of now. However not sure what causes this behavior change, please help.


Solution

  • I suspect that it's the use of @PropertySource that is causing the difference in behaviour. @PropertySource("classpath:application.properties") will load the properties from the first application.properties resource found on the classpath, irrespective of how spring.config.location and spring.config.additional-location have been configured.