在本地开发用windows的没有出现乱码,在CentOS上运行的时候出现乱码.
1.修改中文的编码方式 (成功) env.properties为ANSI格式
先设置idea编码格式,utf-8,
将中文转成Unicode编码方式,然后替换配置文件中的对应中文,这样加载进去的时候就是中文,乱码问题完美解决.
env.properties有中文如下
#是否调用测试接口,为false为正式接口,为true为测试接口, 测试接口在代码中修改
KDN_IsTest=false
中文转成ANSI格式以后变为这样:
#u662Fu5426u8C03u7528u6D4Bu8BD5u63A5u53E3,u4E3Afalseu4E3Au6B63u5F0Fu63A5u53E3uFF0Cu4E3Atrueu4E3Au6D4Bu8BD5u63A5u53E3uFF0C u6D4Bu8BD5u63A5u53E3u5728u4EE3u7801u4E2Du4FEEu6539
KDN_IsTest=false
(以下网上找的失败方案)
1.使用PropertySource (该方案失败) env.properties为utf-8
@PropertySource
(value =
"classpath:conf/evn.properties"
,encoding =
"utf-8"
)
public
class
CopyWriteUI {
@Value("${a}") private String a;
}
2.修改applection中引用加入<property name="fileEncoding" value="UTF-8"></property>(该方案失败) env.properties为utf-8
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/env.properties</value>
</list>
</property>
<property name="fileEncoding" value="UTF-8"></property>
</bean>