美文网首页Java 杂谈微服务框架学习
隐蔽的坑,Spring Boot application.pro

隐蔽的坑,Spring Boot application.pro

作者: Java_or_PHP | 来源:发表于2018-04-25 10:02 被阅读302次

默认情况下,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 看到的就是这样的。


image.png

根据 StackOverFlow 上的说法,想在配置文件里使用utf-8,可以使用 YAML 做配置文件。

这个帖子的下面,有人给出了一个补充:

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

但是,对于已经使用了 application.properties 的项目,这样很不方便编辑了。

搜了一下,有人也给出了解决方案

  1. IntelliJ idea的话:
    setting-> 搜索 file encoding 然后都选择utf-8,勾上transparent,重新打开配置文件


    image.png
  2. eclipse 编辑器下
    Alt + Enter,Text file encoding ,修改默认的编码方式为utf-8

相关文章

网友评论

    本文标题:隐蔽的坑,Spring Boot application.pro

    本文链接:https://www.haomeiwen.com/subject/gteelftx.html