UTF-8 encoding of application.properties attributes in Spring-Boot
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Encoding problems in application.properties usually show up only after you add accented characters, non-Latin text, or symbols that move between editors, build tools, and runtime. In Spring Boot, the safest approach is to treat UTF-8 as an end-to-end contract: save the file as UTF-8, load it consistently, and verify that the bound values still contain the expected characters. Most real failures come from one stage in that chain silently using a different encoding.
What Actually Breaks
There are three common failure modes:
- The file is saved in the wrong encoding by the editor.
- The build process rewrites the file with another encoding.
- The application loads the value correctly, but later output uses a different charset.
That means an apparently simple property such as a greeting or city name can be corrupted even when Spring Boot itself is not the real problem.
Keep the Property File in UTF-8
Start with the file itself. Save application.properties as UTF-8 and keep special characters directly in the source.
If you open the file in an editor that assumes another encoding, those values can already be damaged before the application starts. Keep the editor project encoding explicit and consistent across the team.
Bind and Verify the Values
A simple @ConfigurationProperties class is a good way to prove the values survive loading.
Then print the values at startup:
If the output is already wrong here, the corruption happened before business code touched the data.
Watch the Build Tooling
Maven and Gradle can transform resources. If resource filtering is enabled, lock encoding explicitly so the build does not rewrite files incorrectly.
Maven example:
Filtering is not inherently wrong, but it increases the chance that placeholders and encoding settings interact badly.
@PropertySource Is a Separate Case
If you load extra property files manually with @PropertySource, be explicit about encoding. That path is more likely to cause confusion than standard Boot config loading.
This is especially important in older codebases where custom property loading predates current Boot conventions.
Test the Contract
A small integration test prevents future regressions when the build changes.
This catches editor, build, and loading drift early.
Common Pitfalls
- Saving
application.propertiesin a non-UTF-8 editor encoding. - Enabling resource filtering without locking build encoding explicitly.
- Blaming Spring Boot when the corruption actually happens in output or logging.
- Forgetting to specify encoding on custom
@PropertySourcefiles. - Skipping automated tests for non-ASCII configuration values.
Summary
- Treat UTF-8 as an end-to-end contract from source file to runtime output.
- Keep
application.propertiessaved in UTF-8 with real sample characters. - Verify values through
@ConfigurationPropertiesbinding, not assumptions. - Configure build tooling so resources are not rewritten with the wrong charset.
- Add a focused integration test to stop encoding regressions from reappearing.

