Quick revision
The short answer
We write one application.yml with two documents separated by a line containing ---: the first sets logging.level.root to INFO, and the second starts with spring.config.activate.on-profile: dev and sets it to DEBUG. When dev is active, values in the second document override the first. We activate the profile with spring.profiles.active=dev, for example as SPRING_PROFILES_ACTIVE=dev or --spring.profiles.active=dev, and never from inside a profile-specific document, where Spring Boot does not allow it.
What to remember
In this answer, we wrote a single application.yml with two documents separated by ---, where the second uses spring.config.activate.on-profile: dev to override the logging level. When dev is active, the later document wins key by key; when it is not, that document is skipped. We activate dev through spring.profiles.active, as an environment variable, a command line argument or a system property, and we remember that spring.profiles.active cannot be set inside a profile-specific document; profile groups are the right way to combine profiles.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We write one application.yml with two documents separated by a line containing ---: the first sets logging.level.root to INFO, and the second starts with spring.config.activate.on-profile: dev and sets it to DEBUG. When dev is active, values in the second document override the first. We activate the profile with spring.profiles.active=dev, for example as SPRING_PROFILES_ACTIVE=dev or --spring.profiles.active=dev, and never from inside a profile-specific document, where Spring Boot does not allow it.
Why this question is asked
Most teams need small differences between local development and other environments, and the most common one is logging: we want detailed logs on a laptop and quieter logs everywhere else. Spring Boot lets us keep both settings in a single file, which is easy to read, but the syntax has changed over the years and the old spring.profiles key no longer works in Spring Boot 3, so interviewers like to see whether we know the current form. In this answer, we will recap profiles and multi-document YAML, write the file, see how the override works, activate the profile in several ways, and look at the rule that trips people up: where spring.profiles.active may not appear.
1A Quick Recap of Profiles and Multi-Document Files
A profile is a named set of configuration that we switch on when we need it, such as dev, test or prod. Beans and property values can be tied to a profile, and they only take effect when that profile is active.
YAML allows several documents in one file, separated by a line with three dashes, ---. Spring Boot reads each document as a separate block of properties, in order from top to bottom. A document can say that it only applies when a profile is active, using the key spring.config.activate.on-profile. Documents without that key always apply.
2Writing the File
Here is the whole file. The first document is the default and applies always. The second applies only when the dev profile is active.
Notice that the on-profile key sits under spring.config.activate. Before Spring Boot 2.4 we wrote spring.profiles: dev for the same purpose; that form is no longer supported in Spring Boot 3, and using it makes startup fail with an error about an invalid property, so check old files when upgrading. In a .properties file the same structure works with a line of #--- between documents.
3How the Override Works
Spring Boot reads both documents, but only the ones whose conditions match go into the Environment. Later documents in the same file take precedence over earlier ones, so when dev is active, logging.level.root is defined twice and DEBUG, from the second document, wins. When dev is not active, the second document is skipped completely and INFO is the only value.
- Read document 1root: INFO, always applies
- Is the dev profile active?
spring.profiles.activecontains devYesApply document 2: root becomes DEBUGNoSkip document 2: root stays INFO
2 steps in order. Play them, or step through them one at a time.
The override is per key, not per document. If the default document also set logging.level.com.example: WARN, that value would stay in force in dev, because the dev document does not mention it. So we only need to write the values that differ.
4Activating the Profile
The profile is switched on with the property spring.profiles.active, and like any property it can come from several sources. Which one we choose depends on who decides: a developer on a laptop, an IDE run configuration, or the deployment.
We can also activate several profiles with a comma-separated list, such as dev,local-db. For tests, @ActiveProfiles("dev") on the test class does the same job without touching the environment.
5Where spring.profiles.active May Not Appear
It is tempting to put spring.profiles.active in a document so that one profile switches on another. Spring Boot does not allow that inside a profile-specific document, that is, a document with spring.config.activate.on-profile or a file such as application-dev.yml. The reason is that activation must be settled before profile-specific documents are chosen; letting them change the active profiles would make the result depend on the order of evaluation.
If we want dev to always bring local-db with it, the right tool is a profile group in the default document: spring.profiles.group.dev: local-db. Activating dev then activates both. And setting spring.profiles.active in the default document of a packaged file is allowed but rarely wise, because it makes the jar choose its own environment.
6Follow-up questions
What is the difference between spring.profiles.active and spring.profiles.include?
active replaces the set of active profiles with the given list, while include adds profiles on top of whatever is active. Like active, include cannot be used in a profile-specific document. Profile groups are usually the clearer way to say that one profile brings others.
Would you put this in application-dev.yml instead?
Either works. A separate application-dev.yml is loaded automatically when dev is active and is easy to find; a multi-document application.yml keeps everything for a small service in one file. For larger configuration, separate files are easier to review.
What happens with no active profile?
Spring Boot uses the default profile, called default. Documents with on-profile: default would apply in that case, and the startup log says No active profile set, falling back to 1 default profile.
7Conclusion
In this answer, we wrote a single application.yml with two documents separated by ---, where the second uses spring.config.activate.on-profile: dev to override the logging level. When dev is active, the later document wins key by key; when it is not, that document is skipped. We activate dev through spring.profiles.active, as an environment variable, a command line argument or a system property, and we remember that spring.profiles.active cannot be set inside a profile-specific document; profile groups are the right way to combine profiles.
Open with
I would write one application.yml with two YAML documents separated by a line of three dashes. The first document has logging.level.root set to INFO and applies always. The second starts with spring.config.activate.on-profile set to dev, and sets logging.level.root to DEBUG, maybe with org.hibernate.SQL at DEBUG too.
Then, if they want more
Spring Boot reads the documents in order and later ones override earlier ones key by key. So when dev is active the root level becomes DEBUG, and when it is not, the second document is skipped and INFO stays. The old spring.profiles key for this no longer works in Spring Boot 3, so I always use spring.config.activate.on-profile.
To activate the profile, I set spring.profiles.active to dev. In a container that is usually the SPRING_PROFILES_ACTIVE environment variable, on the command line it is --spring.profiles.active=dev, and with the Maven plugin it is -Dspring-boot.run.profiles=dev. In tests I would use @ActiveProfiles.
One rule to remember is that spring.profiles.active, and include too, cannot be set inside a profile-specific document or file, because activation has to be decided before those documents are chosen, and Spring Boot fails startup if I try. If I want dev to bring another profile with it, I use a profile group in the default document instead.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 3, Spring Boot 2.4
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Write a single application.yml that sets logging to INFO by default and DEBUG when the...": https://scrivio-interview-library.netlify.app/spring-boot/externalized-configuration/2295095ef1/