1

I have specified an external properties file to a Spring Boot app by setting spring.config.additional-location in the SpringApplicationBuilder.

new SpringApplicationBuilder(MyApplication)
            .properties(['spring.config.additional-location': myExternalProperties])
            .run(myArgs)

This works insofar as it allows me to override properties in the application.properties file using myExternalProperties.

However, myExternalProperties are in turn overridden by any profile-specific properties, e.g. application-myProfile.properties.

I understand this to be consistent with Spring's prioritization of Externalized Configuration, but I want myExternalProperties to override even profile-specific properties.

How can I achieve that order of priority? I do not control the file name or location of myExternalProperties. This variable is a System property that is preset in the environment.

I have been looking at Profile-specific Properties and in particular this quote.

If you have specified any files in spring.config.location, profile-specific variants of those files are not considered. Use directories in spring.config.location if you want to also use profile-specific properties.

I assume this note applies equally to spring.config.additional-location, but without control over the property file name or location I don't think that helps me.

jaco0646
  • 15,303
  • 7
  • 59
  • 83

1 Answers1

1

I'm afraid it cannot be achieved in a non-hacky way.

The docs state:

Profile-specific files always overriding the non-specific ones.

Also:

If several profiles are specified, a last-wins strategy applies. For example, profiles specified by the spring.profiles.active property are added after those configured through the SpringApplication API and therefore take precedence.

Could you consider using profile based configuration for myExternalProperties?

You can even use env vars as placeholders. Hope this helps: Env vars in Spring boot properties

J11
  • 426
  • 1
  • 6
  • 17