How Spring Boot loads properties or yml or yaml file

Did you ever notice Spring boot automatically reads the configuration file if we define the configuration file with the name or application.yml? In this post, we will see How Spring Boot loads properties or yml or yaml file. If we define these files with some different name Spring Boot will not load. In that case, we need to use some other annotation to load the custom configuration file.

In it has been defined as a constant which tells about the default location where these configurations should be kept.

class ConfigFileApplicationListener {

private static final String DEFAULT_SEARCH_LOCATIONS = "classpath:/,classpath:/config/,file:./,file:./config/";

private static final String DEFAULT_NAMES = "application";


The following combination is allowed as the default file name.

It appends .properties or .yml or yaml extension later.

Let’s see list of files which loads default by Spring Boot.

We get how it read from some specific location. why we should keep properties file in some location. But the file name is applicationonly. It should be something called or application.yml.

Default locations allow reading file automatically?

Let’s see the default directory locations that are used to keep the file.

The default location for the properties file.


If you put in the resources folder then it will be considered in classpath:/

There are two predefined classes PropertiesPropertySourceLoader and YamlPropertySourceLoader in org.springframework.boot.env package that implements the PropertySourceLoader interface.

public interface PropertySourceLoader {

	List<PropertySource<?>> load(String name, Resource resource) throws IOException;


Can we use both and appication.yml at the same time?

No. We should not. We may get unexpected result.

We can override the default file name, using @PropertyResource annotation, and define a custom configuration file.

That’s all about How Spring Boot loads properties or yml or yaml file example.

You may like.

Other Spring Data JPA and Hibernate tutorials.