Spring Profiles
Profiles in the Spring framework give you the ability to change application configurations based on the environment that the application is deployed to and is valuable in multi-environment deployments. Usually an application has to be deployed to a test or pre-production or production environment where these environment settings differ in some way, profiles give you the ability to manage multiple environment configuration sets without having to create multiple containers. Another scenario where profiles may be of use is when an application has to run in two different production domains, a live vs. cold environment to cater for disaster recovery.
Set up a profile with application.yaml
An easy way of changing application configuration based on profiles is through the application.yaml file which Spring supports natively. The traditional application.properties file becomes the application.yaml file in the application that will be deployed to multiple environments or a distributed cluster which enables properties to be changed by profile. Spring.profiles is the key value in the yaml file to indicate that all the properties below it are specific to that profile.
An example of an application.yaml file with profiles:
spring:
profiles: dev
server:
port: 8080
---
spring:
profiles: test
server:
port: 9090
To enable a specific profile within the application, the spring.profiles.active environment variable is set in the run configuration to the profile name or injected via a program argument in command line using -Dspring-boot.run.arguments.
Spring will convert command line arguments to properties and add them as environment variables.


