Config Files: .properties vs .yml, Application vs Bootstrap

1. .properties vs .yml (YAML)

Feature .properties .yml / .yaml
Format Key-value pairs (key=value) Hierarchical (uses indentation):key: value
Preferred for Simple configs Complex, nested configs
Structure Sequential, non-nested Supports nested/hierarchical data
Repetition Keys often repeated Reuses parent keys (no repetition)
Multi-profile Needs separate files for each profile Multiple profiles in one file

Priority between .properties and .yml

If both application.properties and application.yml exist in the same location,Spring Boot gives priority to application.properties

application.yml

yml server: port: 8081

application.properties

server.port=8088
Result: Port = 8088 (because .properties overrides .yml)

2. application.properties / application.yml

  • Default configuration file for Spring Boot.
  • Used for:

    • App-specific configs (DB, server, security)
    • Profiles (application-dev.yml, etc.)
  • Location: src/main/resources/

3. bootstrap.properties / bootstrap.yml

  • Used for:

    • External config sources (e.g., Spring Cloud Config)
    • Service discovery or environment setup
  • Needed only when using Spring Cloud / Config Server.

  • Location: src/main/resources/

Loading Order

File Loaded Priority
bootstrap.yml / bootstrap.properties First Lower
application.yml / application.properties After Higher

Example

spring:
  application:
    name: my-service
  cloud:
    config:
      uri: http://localhost:8888
  server.port=8081
  spring.datasource.url=jdbc:mysql://localhost:3306/test
server:
  port: 8081
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test

↑ Back to top