Migrating an application from properties files to YAML means converting each flat, dot-separated key into YAML's nested structure while preserving the exact same effective configuration values.
Key Points: • Create equivalent .yml files, restructuring dot-separated keys (e.g. server.port) into nested mappings (server: port:). • Pay close attention to YAML's indentation and list syntax, since a small formatting mistake changes meaning silently rather than throwing an obvious error. • Keep both formats side by side temporarily and diff the effective Environment (e.g. via the /actuator/env endpoint) to confirm nothing was lost in translation. • Update any profile-specific files (application-prod.properties → application-prod.yml) consistently, since Spring Boot won't merge a leftover properties file with a new YAML file for the same profile without care. • Once verified, remove the old properties files entirely to avoid ambiguity about which file is authoritative.
Example: server.port=8080 and spring.datasource.url=jdbc:... in a properties file become nested server: port: 8080 and spring: datasource: url: jdbc:... entries in YAML, which is easier to scan once profiles and nested lists are involved.
Code Example:
# before: application.properties
server.port=8080
spring.datasource.url=jdbc:postgresql://localhost/db
# after: application.yml
server:
port: 8080
spring:
datasource:
url: jdbc:postgresql://localhost/dbInterview Tip: A concise interview answer is:
"I'd convert each properties file into an equivalent YAML file, being careful with indentation since YAML errors fail silently rather than loudly. I'd verify the migration by comparing the effective configuration through Actuator's /env endpoint before removing the old properties files, to make sure nothing changed unintentionally."