The application.yml file is the main configuration file of a Spring Boot application. Spring Boot reads it at startup from the classpath (or from external locations) and binds its values to the framework, to your beans and to auto-configuration. It does the same job as application.properties but uses YAML, which expresses nested settings without repeating long key prefixes.
You put server settings, datasource URLs, logging levels, custom properties and profile-specific overrides in it, so behaviour changes without recompiling.
Spring Boot's auto-configuration looks at the properties in this file to decide how to configure the application. A small example:
Here server.port changes the embedded web server port, spring.datasource.* configures the connection pool, and logging.level.* sets log verbosity. ${DB_PASSWORD} is a placeholder resolved from an environment variable, so the secret is not stored in the file.
YAML uses indentation for nesting, while a properties file repeats the full key on each line.
| Aspect | application.yml | application.properties |
|---|---|---|
| Nesting | Indentation | Dotted keys |
| Lists | - item lines | key[0]=item |
| Comments | # | # or ! |
| Multiple profiles in one file | Yes, with --- documents | Yes, with #--- |
| Risk | Indentation mistakes | Repetitive keys |
Lists are a place where YAML reads better.
Use spaces only, never tabs. Quote values that YAML could misread, such as "yes", "no" or "1.10", when you need text.
Spring Boot binds the file to your classes. The recommended approach is a type-safe @ConfigurationProperties record.
Register it with @ConfigurationPropertiesScan or @EnableConfigurationProperties(AppProperties.class). Relaxed binding maps allowed-origins in YAML to allowedOrigins in Java. For a single value, @Value("${server.port}") also works, but it has no validation or grouping.
application.yml supports profiles in two ways. You can create separate files such as application-prod.yml, or you can place several documents in one file, separated by ---.
Activate a profile with SPRING_PROFILES_ACTIVE=prod or --spring.profiles.active=prod. The property spring.config.activate.on-profile replaced the old spring.profiles key in Spring Boot 2.4. Values from active profiles override the defaults.
Spring Boot loads application.yml from these locations, with later locations overriding earlier ones:
/config package./config subdirectory of the current directory and its immediate subdirectories.Above all files sit environment variables, JVM system properties and command-line arguments, which have higher precedence. You can also import extra files with spring.config.import, or point to another file with --spring.config.location.
@ConfigurationProperties over scattered @Value annotations.spring-boot-configuration-processor so your IDE can autocomplete your own properties.application-local.yml.No. Spring Boot has defaults for nearly everything, so the file is optional. You only add it when you need to change defaults or define your own properties.
Yes, both are loaded. If the same key appears in both in the same location, the .properties value takes precedence.
The usual causes are a wrong indentation level, a tab character, a misspelt key, or the file sitting in the wrong folder. Check the Actuator env endpoint to see the loaded values.
Not automatically. Restart the application, or use Spring Cloud Config with refresh, or Spring Boot DevTools during development.
application.yml is Spring Boot's central, readable configuration file. It sets server, datasource, logging and custom properties, supports profiles and multi-document files, and binds cleanly to @ConfigurationProperties. Keep secrets in the environment and remember that command-line arguments and environment variables override it.