application.properties and application.yml are two formats for the same thing — externalized configuration — and Boot binds both into the same Environment. The real interview content isn't the syntax; it's the override order that decides which value wins when a key is defined in several places.
The two formats
# application.properties
spring.datasource.url=jdbc:postgresql://localhost/shop
spring.jpa.hibernate.ddl-auto=validate
logging.level.com.acme=DEBUG
# application.yml — hierarchical, less repetition
spring:
datasource:
url: jdbc:postgresql://localhost/shop
jpa:
hibernate:
ddl-auto: validate
logging:
level:
com.acme: DEBUG
YAML is nicer for nested structure and lists; .properties is flat and avoids YAML's indentation/type gotchas (on/off/yes parse as booleans). If both files exist, .properties is loaded after .yml, so a key in .properties overrides the same key in .yml. Don't rely on that — pick one format.
The property hierarchy (override order)
Boot layers many property sources; later sources override earlier ones. Highest-priority first, roughly:
- Command-line arguments (
--server.port=9090) SPRING_APPLICATION_JSON(inline JSON)- OS environment variables (
SERVER_PORT=9090— relaxed binding) - Java system properties (
-Dserver.port=9090) - Profile-specific files outside the jar (
application-prod.ymlnext to the jar) - Profile-specific files inside the jar
- Plain
application.yml/.propertiesoutside the jar - Plain files inside the jar
@PropertySourceon@Configuration- Default properties (
SpringApplication.setDefaultProperties)
Two rules cover most cases: command line / env vars beat files, and profile-specific beats plain, external beats packaged.
Relaxed binding
A single property is reachable under several spellings, which is why env vars work:
spring.datasource.url == SPRING_DATASOURCE_URL == spring.datasource_url
Kebab-case (my-prop), camelCase, and UPPER_UNDERSCORE all bind to the same target.
Profile groups and multi-document files
A single YAML file can hold several profile-specific documents separated by ---:
spring:
config:
activate:
on-profile: prod
server:
port: 8443