我使用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
为什么?
答案 0 :(得分:2)
尝试,在属性源中指定编码
@PropertySource(value = "classpath:/myprop.properties", encoding="UTF-8")
并且,您应该在启动应用程序之前设置系统编码
System.setProperty(" file.encoding"," UTF-8");
或通过命令行=> -Dfile.encoding=UTF-8