override command line spring properties with bootstrapyml

Command line argument(-Dspring.profiles.active=e2) will always override your properties file, no matter how many hardcoded profiles you specify in your yaml file. I would suggest you to add additional profile to be set programatically at the runtime and keep two property files with -profilename before the .yml extension.

This could be done as follows:


public static void main(String[] args) {
    SpringApplication app = new SpringApplication(DemoApplication.class);


// Keep all the properties which is specific to e2 profile.


   // Keep all the properties which is specific to cron profile.

In this way, you can keep both the profiles in use .But, if a property is common in both the bootstrap files, then program will pick the property from that bootstrap file whose profile matches with the runtime args : -Dspring.profiles.active

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top