默認(rèn)情況下,Spring Boot application.properties 是以 iso-8859-1 的格式編碼的。
不是UTF-8
不是UTF-8
不是UTF-8
不是ISO-8859-1 編碼的字符,都是以 unicode escapes 的形式存在的,比如:
personName=\u4F59\u5E38\u6D77
用notepad++ 或者 Vim 打開 application.properties 看到的就是這樣的。

根據(jù) StackOverFlow 上的說法,想在配置文件里使用utf-8,可以使用 YAML 做配置文件。
這個(gè)帖子的下面,有人給出了一個(gè)補(bǔ)充:
I've faced with the same problem. In Spring Boot there are 2 PropertySourceLoader which are used to load properties in application:
PropertiesPropertySourceLoader - supports UTF-8 only when load from XML
YamlPropertySourceLoader - supports UTF-8, but you have to change configuration format to use it
YamlPropertySourceLoader 支持UTF-8
但是,對(duì)于已經(jīng)使用了 application.properties 的項(xiàng)目,這樣很不方便編輯了。
搜了一下,有人也給出了解決方案
-
IntelliJ idea的話:
setting-> 搜索 file encoding 然后都選擇utf-8,勾上transparent,重新打開配置文件
image.png eclipse 編輯器下
Alt + Enter,Text file encoding ,修改默認(rèn)的編碼方式為utf-8
