Spring Boot 2.4 Multi-Profile Configuration: From spring.profiles to spring.config.activate.on-profile

This article explains how Spring Boot 2.4 changes the way multi‑environment configurations are defined and activated, replacing the old spring.profiles property with spring.config.activate.on-profile and showing how to specify and launch profiles both in YAML files and via command‑line arguments.

Programmer DD
Programmer DD
Programmer DD
Spring Boot 2.4 Multi-Profile Configuration: From spring.profiles to spring.config.activate.on-profile

In the latest Spring Boot 2.4, the configuration loading mechanism has been significantly changed. This article explains the differences in multi‑environment configuration between previous versions and 2.4.

Multi‑environment configuration

Before 2.4

Previously we defined different profiles in YAML using spring.profiles, for example:

spring:
  profiles: "dev"

name: dev.didispace.com

---
spring:
  profiles: "test"

name: test.didispace.com

---
spring:
  profiles: "prod"

name: prod.didispace.com

After 2.4

From 2.4 onward the spring.profiles property is replaced by spring.config.activate.on-profile. The same configurations become:

spring:
  config:
    activate:
      on-profile: "dev"

name: dev.didispace.com

---
spring:
  config:
    activate:
      on-profile: "test"

name: test.didispace.com

---
spring:
  config:
    activate:
      on-profile: "prod"

name: prod.didispace.com

Activating a profile at startup

When launching the application you still set the active profile with spring.profiles.active, whose value must match the name defined by spring.config.activate.on-profile. For example:

java -jar myapp.jar -Dspring.profiles.active=dev

The startup log will show the activated profile:

2020-12-16 16:34:20.614  INFO 5951 --- [           main] c.d.chapter12.Chapter12Application       : The following profiles are active: dev

You can also set spring.profiles.active directly in application.yml to define a default profile, typically “dev” for local development, while production environments are usually activated via command‑line arguments.

Code example

The related example code is available in the chapter1-2 directory of the repository:

GitHub: https://github.com/dyc87112/SpringBoot-Learning/

Gitee: https://gitee.com/didispace/SpringBoot-Learning/

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backend DevelopmentConfigurationSpring BootProfilesSpring 2.4
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.