环境变量不支持UTF-8?

时间:2016-12-15 12:30:37

标签: java spring utf-8 properties

我使用Spring @PropertySource注释根据环境变量加载属性文件。 (在Windows中的System variables of this window中设置)

我设置MY_APP = C:\Cliché

现在我的@Configuration课程也注明了:

@PropertySource(value = "file:${MY_APP}/config/my.properties"

但Spring无法加载该文件,因为它似乎将URL /路径解析为:C:\Clich,\config\my.properties

为什么?

1 个答案:

答案 0 :(得分:2)

尝试,在属性源中指定编码

@PropertySource(value = "classpath:/myprop.properties", encoding="UTF-8")

并且,您应该在启动应用程序之前设置系统编码

System.setProperty(" file.encoding"," UTF-8");

或通过命令行=> -Dfile.encoding=UTF-8