Including profiles in spring boot 2.4.0 version
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Spring Boot 2.4.0 overhauled how external configuration and profiles work. The previous spring.profiles and spring.profiles.include properties were replaced with a new activation model built around spring.config.activate.on-profile. If you are upgrading from an earlier Spring Boot version, understanding these changes is essential to avoid broken configurations. This article covers the new profile activation syntax, profile groups, multi-document YAML files, and the migration steps you need to follow.
What Changed and Why
Before 2.4.0, you could write this in an application.yml to restrict a document section to a specific profile:
The problem was that spring.profiles served double duty: it both activated profiles and filtered which document sections loaded. This created confusing interactions when combining spring.profiles with spring.profiles.include. Spring Boot 2.4.0 separated these concerns by introducing dedicated properties.
The New Activation Model
spring.config.activate.on-profile
To conditionally load a section of configuration, use spring.config.activate.on-profile instead of the old spring.profiles:
This property accepts profile expressions, including ! (not), & (and), and | (or):
Multi-Document YAML with ---
Spring Boot 2.4.0 brought multi-document support to application.yml (using --- separators) and even to .properties files (using #---). Each document section can have its own activation condition:
The equivalent in application.properties uses #--- as the document separator:
Profile Groups
Spring Boot 2.4.0 introduced profile groups, which let you activate multiple profiles under a single group name. This is useful when an environment requires several profiles to be active simultaneously:
Now activating the production profile (via --spring.profiles.active=production) automatically activates proddb, prodmq, and prodmetrics as well. This replaces many uses of the old spring.profiles.include.
Migration Steps
If you are upgrading from Spring Boot 2.3 or earlier, follow these steps:
- Replace
spring.profileswithspring.config.activate.on-profile. Search your YAML and properties files forspring.profiles:(used as a document filter) and rewrite it. - Replace
spring.profiles.includewith profile groups. If you were usingspring.profiles.includeinside a profile-specific document, move that logic intospring.profiles.groupin the default (non-profile-filtered) document. - Enable the legacy mode if needed. If you cannot migrate immediately, set
spring.config.use-legacy-processing=truein your mainapplication.propertiesto restore pre-2.4 behavior. This is a temporary bridge -- plan to remove it. - Test multi-document ordering. In the new model, later documents override earlier ones. Verify that your property precedence is correct by running with
--debugand inspecting thePropertySourcelog output.
Common Pitfalls
- Using
spring.profilesin a profile-activated document. In 2.4.0+, placingspring.profilesinside a----separated section throws an error unless legacy processing is enabled. Always usespring.config.activate.on-profileinstead. - Placing
spring.config.activate.on-profilein the first document. The first document in a multi-document file is the default and cannot have an activation condition. Spring Boot will reject this with a configuration error. Put profile-specific sections in subsequent documents only. - Forgetting the
#---separator in properties files. Multi-document support in.propertiesfiles requires exactly#---on its own line. Using# ---(with a space) or---(without the#) does not work and silently treats the entire file as a single document. - Mixing
spring.profiles.includewith the new model. Usingspring.profiles.includeinside a profile-activated document is not allowed in the new processing model. Move inclusion logic tospring.profiles.groupin the default document section. - Not testing profile activation order. The new model processes documents top to bottom, with later values overriding earlier ones. If you reorder your
---sections or add new ones, previously working property values can be silently overwritten. Always verify with the--debugflag.
Summary
- Spring Boot 2.4.0 replaced
spring.profiles(document filter) withspring.config.activate.on-profile, which supports profile expressions likeproduction & !debug. - Multi-document YAML (
---) and properties (#---) files let you keep all profile-specific configuration in a single file. - Profile groups (
spring.profiles.group) replace most uses ofspring.profiles.includeand let you activate multiple profiles under one name. - Set
spring.config.use-legacy-processing=trueas a temporary bridge during migration, but plan to remove it. - Always test property precedence after migration because document ordering determines which values win.

