springBoot中.properties文件中中文乱码解决

第一步:Eclipse中进行如下菜单设置:

Window - Preferences - General - Content Types,右侧Text - java Properites File 在Default encoding中输入UTF-8,点击Update。

如果自定义配置文件未更新编码格式,可在属性中手动设置为utf-8。

第二步:安装PropertiesEditor。在Help - Eclipse Marketplace 中查找、安装PropertiesEditor。通过PropertiesEditor编辑的配置文件,不会再出现乱码。
(方法一)
1、首先,在eclipse中点击“help”-"Install New Software"。
2,、点击右侧的“Add”按钮。
3、输入
Name:properties。
Location:http://propedit.sourceforge.jp/eclipse/updates/
然后点击OK。
4、稍等两分钟,就会出现插件列表,选择PropertiesEditor,然后Next.
5、继续Next。
6、点击“I accept ……”,然后Finish.。
7、安装完成后点击“Restart Now”重启eclipse。
8、此时在properties文件上点右键,点击“Open With"-"PropertiesEditor",打开文件,现在就可以直接输入中文了

方法二:
1.下载离线安装文件:http://sourceforge.jp/projects/propedit/downloads/40156/jp.gr.java_conf.ussiy.app.propedit_5.3.3.zip/
2.安装与检验
将得到的文件直接解压,可得到这样一个文件夹 jp.gr.java_conf.ussiy.app.propedit_5.3.3 ,直接将该文件夹复制到 Eclipse目录下覆盖插件文件夹。
springBoot中.properties文件中中文乱码解决

3.重启Eclipse。
4.选中 .properties 文件,右键 - Open With ,你会看到多了一个 PropertiesEditor 子菜单。
5.将PropertiesEditor设为默认的打开方式
工具栏->Window->Preferences->General->Editors->File Associations,添加一个
.properties。
下方的 Associated editors 栏里有 PropertiesEditor 项,选中,点击 Default 按钮。
双击properties文件默认就会用PropEditor打开了。
springBoot中.properties文件中中文乱码解决

springBoot中.properties文件中中文乱码解决

另外,读取配置文件时,自定义配置文件类中@PropertySource注解中也可指明编码格式。如下:

@PropertySource(value= {"classpath:config.properties"},encoding="UTF-8")
当然,如果你安装了PropertiesEditor就没必要这么使用注解了。

最后同样重要的是eclipse 版本是
springBoot中.properties文件中中文乱码解决
只要设置第一步就可以了

猜你喜欢

转载自blog.51cto.com/11864647/2285311