Spring override environment variable from application.properties

39 views Asked by At

I have a spring project, which has an application.properties file, as well as an application-profile1.properties and an application-profile2.properties.

Inside application-profile1/2.properties there is one property, let's call it my.first.property. The behaviour I need is the following:

In application-profile1.properties, my.first.property will have a hardcoded value, something like: my.first.property=propertyvalue. In application-profile2.properties, my.first.property will try to import the value from the environment, something like: my.first.property=${MY_FIRST_PROPERTY}

The problem is, that it doesn't matter what I do, in my @Configuration class, when I declare a variable myFirstPropery, spring will always look for an environment variable that matches, and will ignore the application.properties file if it finds a match. How can I achieve the desired behaviour? Is there a way to prevent spring from prioritising environment variables over my .properties files?

0

There are 0 answers