Understanding Spring Boot Config File Priority: properties vs yaml

Spring Boot loads configuration files in a defined order, giving higher priority to application.properties over application.yaml, and searches locations such as file:./config/, file:./, classpath:/config/, and classpath:/, with merging behavior that interviewers often test.

Programmer DD
Programmer DD
Programmer DD
Understanding Spring Boot Config File Priority: properties vs yaml

1. Introduction

Today I wondered what happens when Spring Boot configuration files contain both application.properties and application.yaml . I tested and found that the priority order is properties > yaml. Although mixing these types is rare, interviewers may ask about it, so it's worth remembering. The priority of Spring Boot configuration file locations is also frequently used, so I summarize it here.

Based on Spring Boot 2.3.3.RELEASE

2. Configuration File Loading Order

In Spring Boot, the ConfigFileApplicationListener handles loading configuration files. The key loading logic is shown in the following code:

private Set<String> getSearchLocations() {
    // CONFIG_ADDITIONAL_LOCATION_PROPERTY = "spring.config.additional-location"
    Set<String> locations = getSearchLocations(CONFIG_ADDITIONAL_LOCATION_PROPERTY);
    // CONFIG_LOCATION_PROPERTY = "spring.config.location"
    if (this.environment.containsProperty(CONFIG_LOCATION_PROPERTY)) {
        locations.addAll(getSearchLocations(CONFIG_LOCATION_PROPERTY));
    } else {
        locations.addAll(
            // DEFAULT_SEARCH_LOCATIONS = "classpath:/,classpath:/config/,file:./,file:./config/*/,file:./config/"
            asResolvedSet(ConfigFileApplicationListener.this.searchLocations, DEFAULT_SEARCH_LOCATIONS));
    }
    return locations;
}

In any case, configuration files under spring.config.additional-location are loaded first. If we specify a custom configuration path via spring.config.location (usually via command line), files are loaded from that path. If not, the following locations are searched in order (top to bottom):

file:./config/
file:./config/*/
file:./
classpath:/config/
classpath:/

3. Common Misconception

A common mistake is thinking that when both application.properties and application.yaml exist, only one is loaded. In fact, both are loaded and their contents are merged according to priority; the higher‑priority file overrides overlapping properties.

The same merging mechanism applies when evaluating DEFAULT_SEARCH_LOCATIONS paths.

Priority means all configuration files are loaded, and overlapping properties are merged based on priority.

4. Conclusion

The Spring Boot configuration file loading mechanism is an important topic for daily configuration extension, multi‑environment setups, and deployment, and it is frequently asked in interviews. Understanding it is essential.

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.

ConfigurationSpring BootYAMLproperties
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.