第一步:Eclipse中进行如下菜单设置:
Window - Preferences - General - Content Types,右侧Text - java Properites File 在Default encoding中输入UTF-8,点击Update。
如果自定义配置文件未更新编码格式,可在属性中手动设置为utf-8。
第二步:安装PropertiesEditor。在Help - Eclipse Marketplace 中查找、安装PropertiesEditor。通过PropertiesEditor编辑的配置文件,不会再出现乱码。
另外,读取配置文件时,自定义配置文件类中@PropertySource注解中也可指明编码格式。如下:
@PropertySource(value= {"classpath:config.properties"},encoding="UTF-8")
当然,如果你安装了PropertiesEditor就没必要这么使用注解了。