Capeta Capeta - 3 months ago 14
Java Question

Spring Boot Application java -jar --property override not working

I've written a Spring Boot Application. I'm running the jar, while running the jar I'm overriding the property file keys for e.g:

java -jar example.jar --spring.profiles.active=test
, but the key is not overriding. What could be the reason for this?

Answer

For command line arguments to override properties, you need the arguments pass into your application's main method into SpringApplication.run.

Your main method should look something like this:

public static void main(String[] args) throws Exception {
    SpringApplication.run(YourApplication.class, args);
}
Comments