How to set UTF-8 character encoding in Spring Boot
Codemia Knowledge Hub ·
Set the server.servlet.encoding properties to UTF-8 and force them, then check that every other layer (source files, templates, the JDBC connection and the database) also uses UTF-8. In a Spring Boot web app, garbled non-ASCII text in request bodies, form posts or responses usually means one layer read the bytes with the wrong encoding.
Servlet encoding properties
For servlet-based Spring Boot applications, these properties are the standard place to configure it.
In application.properties:
Or in application.yml:
This makes UTF-8 the default request and response encoding and forces it wherever the servlet stack supports that.
These settings cover the HTTP layer:
- Reading request parameters and form submissions.
- Writing response content.
- Keeping servlet-level text processing consistent.
If characters are still corrupted afterwards, the problem is somewhere else, such as the database, a template file or a downstream service.
No encoding code needed in controllers
When the app is configured correctly, a controller needs no manual encoding handling:
The response comes out correctly without extra work in the controller.
Source files and templates saved in the wrong encoding
Spring Boot settings cannot fix text that is already stored wrongly. If a .java, .html, .sql or template file is saved in another encoding, the output can still be corrupted. Check that:
- Source files are saved as UTF-8.
- Template files are saved as UTF-8.
- Build tooling does not rewrite resources with a different encoding.
A single file saved incorrectly is a more common cause than the Spring Boot properties.
Database and JDBC encoding
If the app stores multilingual text, the database and connection must support UTF-8 too. A UTF-8 web layer cannot make up for a database with incompatible character settings. A full diagnosis can involve:
- Spring Boot servlet encoding.
- Template or resource file encoding.
- JDBC connection behavior.
- Database column and table character settings.
If persisted data is already wrong, the HTTP layer is not the place to look.
When to use CharacterEncodingFilter
In most modern Spring Boot setups the properties are enough. In an unusual legacy configuration you can still register a custom CharacterEncodingFilter, but only add it when the built-in settings do not solve the problem.
Mistakes that keep text garbled
- Setting UTF-8 for HTTP responses while source or template files use another encoding.
- Expecting servlet encoding settings to fix database-level character problems.
- Copying older property names from outdated examples instead of the current
server.servlet.encodingproperties. - Adding custom filters before checking whether the Boot configuration already covers the case.
- Debugging controller code when the corruption happened earlier in the pipeline.
Related reading
- How to setup multiple connection pools when multiple datasources are used in Spring Boot?
- How to setup multiple topics in a RabbitMQ Java config class using Spring Framework?
- How to setup pre-authentication header-based authentication in Spring Boot?
- How to show all parents and subclasses of a class in IntelliJ IDEA?
- How to shut down a Spring Boot command-line application
- How to shutdown a Spring Boot Application in a correct way?
- How to simplify a null-safe compareTo implementation?
- How to skip corrupt (non-serializable) messages in Spring Kafka Consumer?
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.