spring.profiles.active not honoured

12.4k views Asked by At

In

application.properties 

we have the line

spring.profiles.active=LOCALHOST

In

application-DEV.properties

, we have the line

spring.profiles.active=DEV,dbcache,metrics,AWS

. When running the app with

java -jar app.war -Dspring.profiles.active=DEV

the console output says

The following profiles are active: LOCALHOST

, ie the

-Dspring.profiles.active=DEV 

argument isn't honored, the app still uses the default LOCALHOST profile.

2

There are 2 answers

0
chrylis -cautiouslyoptimistic- On BEST ANSWER

My man page for the java command says:

java [ options ] -jar file.jar [ argument ... ]

That is, JVM options (such as property settings) must go before the -jar (or main class). Anything after that is considered an argument passed to main.

This actually has a purpose and isn't just pedantic--you might have a tool that launches a child JVM (Maven can do this, for example) and want to provide arguments to be passed there.

3
ExploreEv On

Just in case some one is having the same issue as me, make sure your main class args is passed into spring. Hope it helps.

public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}