UTF-8 encoding with Spring Boot 1.1.1

How can I “say” Spring Boot to use the UTF-8 encoding, to show and save German umlauts correctly? We are programming a Java-Webapplication using Sping-Boot 1.1.1 (Release) and as webserver a TomCat7 or Jetty. The database is postgresql or h2 for testing.


I tried it with the properties file (thanks for the answer), but no changes are visible.

The database is also UTF-8… Especially the problem comes, when we send a POST-Request to the Webserver. The Spring-Request-Handler gets already the broken encoded values. In the following you can see a part of the code: (It shows a snippet of the Thymeleaf-Template)

And this is the request handler for that:

@RequestMapping(method = RequestMethod.POST)
public String handleUserUpdate(@ModelAttribute(MODEL) UpdateUserCommand command) {
   //here we cut the broken encoded values

Greetings Stef

What is wrongly encoded? The request or the response? server.tomcat.uri-encoding
is switching the URI
decoding to UTF-8
(this is already the case for Jetty).

But that does not do anything for the request body. By default, Spring MVC decodes that with ISO-8859-1
(that is the default per the servlet spec). You need to specify a body encoding in your request if you want it to be decoded using UTF-8
. Most users are actually using the CharacterEncodingFilter
to achieve the same thing (and ensure consistency).

If that fixes your issue, watch out for #1182
that is meant to provide an auto-configuration for that.

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » UTF-8 encoding with Spring Boot 1.1.1

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录