Want to improve as a dev?

I send a short email every workday about Spring topics, API development and improving as a dev.

I understand and agree to the privacy policy

Property Handling and Profiles - Part 2

21.03.2018 by Jens in Spring Boot | Newsletter

Using –spring.profiles.active is not the only way to set the active profile. Reader Sandeep came up with an excellent question:

Let’s assume that I have three environments: Dev, Staging, and Prod. I will create three property files, one for each environment like application-dev.properties, application-staging.properties, and application-prod.properties. I understand the concept until this point. Now, let’s say I am deploying this on three different servers with Jboss EAP (Wildfly) for each environment, how will I set up the active profile? Could you please help me understand this.

Basically, we have three possible ways to do that. They also work for modern Spring Boot deployments, not just for the war-style.

  1. Using an environment variable available to the Wildfly process. Can be set in the start script or globally.
  2. Adding it as a VM system property when starting the Java process like:

    java -jar Whatever.jar -Dspring.profiles.active=preprod

  3. Include a regular application.properties and set the active profiles in it with


    However, we need to set the particular value somewhere in the build and deploy pipeline. A classic way would be to use a Maven property placeholder in the property file and let Maven filter it. Again using profiles, but this time it is Maven profiles. So, during a preprod b&d, we use a Maven Profile which sets the Spring property spring.profiles.active.

I’ve used all variants in the past, but if it’s possible, I will go with No. 2. It’s the smoothest and fastest way with the lowest implications, at least when operations are willing to do it…

comments powered by Disqus