Database application.yml for Spring boot from applications.properties
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Spring Boot accepts both application.properties and application.yml, and the database settings are the same logical keys in either format. Converting to YAML is mainly about translating flat dotted keys into nested structure while preserving the same meaning. Once the hierarchy is clear, database configuration in application.yml is usually easier to read and maintain than a long properties file.
Convert Flat Properties into Nested YAML
A common application.properties database setup looks like this:
The YAML equivalent is:
That is the main conversion rule:
- dotted segments become nested YAML keys
- scalar values stay scalar values
- indentation matters
The property names themselves do not change, only the representation.
Include Connection Pool Settings
If your application uses the default Hikari connection pool, those settings also move under spring.datasource.hikari.
This structure is easier to scan than the properties equivalent because all datasource and pool configuration stays visually grouped.
Keep Environment-Specific Settings Separate
YAML becomes especially useful when you want profile-specific sections. For example:
That lets one file express shared defaults and profile overrides clearly. For sensitive production credentials, however, environment variables or a secret manager are usually better than hardcoding secrets into the file.
Use Placeholders for Externalized Secrets
A practical YAML setup often combines defaults with environment placeholders:
This means:
- use the environment value if present
- otherwise fall back to the provided default
That makes local development easy without giving up deploy-time configurability.
Watch YAML Syntax Carefully
Most migration errors are not Spring Boot issues. They are YAML syntax errors:
- wrong indentation
- tabs instead of spaces
- misplaced profile separators
- accidentally turning a scalar into a nested object
For example, this is wrong:
because datasource is no longer nested under spring.
When configuration suddenly stops binding after conversion, inspect indentation first. Spring property binding is usually fine; malformed YAML is the more common cause.
Validate the Migration with a Simple Startup
After converting, run the application and verify that the datasource actually binds:
This is a simple sanity check that the app still creates the datasource after the format change.
Common Pitfalls
- Translating dotted property names incorrectly and breaking the nesting structure.
- Misplacing indentation and assuming Spring Boot is the problem instead of YAML syntax.
- Hardcoding secrets in
application.ymlwhen environment placeholders would be safer. - Mixing profile-specific and shared values without clear separators.
- Changing property names during conversion even though only the format needed to change.
Summary
- Converting database config from properties to YAML is mostly a structural transformation.
- Dotted keys become nested YAML sections under the same logical property names.
- '
spring.datasourceandspring.jpasettings map cleanly into YAML.' - YAML is especially helpful for grouping related database and profile-specific settings.
- Validate the conversion with a real application startup so syntax and binding problems are caught early.

