Mathieu Stn
Mathieu Stn

Reputation: 168

Spring MVC application.properties not override by profile file application-dev.properties

I was looking at a way to configure different application.properties file depending on a JVM environnement variable.

I found this documentation on Spring references.

In addition to application.properties files, profile-specific properties can also be defined using the naming convention application-{profile}.properties.

Profile specific properties are loaded from the same locations as standard application.properties, with profile-specific files always overriding the default ones irrespective of whether the profile-specific files are inside or outside your packaged jar.

Then I did that :

Configuration structure

And then added a -Dspring.profiles.active=dev to my JVM options.

Profile option for JVM

I tried to see that my params in dev are used but it isn't the case. Te application loads the data from the application.properties file.

Any idea why?

Upvotes: 3

Views: 1963

Answers (1)

Daniel Chaves
Daniel Chaves

Reputation: 304

Try to modify the default properties file's name to 'application-default.properties', as it is said in the documentation:

The Environment has a set of default profiles (by default [default]) which are used if no active profiles are set (i.e. if no profiles are explicitly activated then properties from application-default.properties are loaded).

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-profile-specific-properties

Upvotes: 3

Related Questions