2016-12-15 107 views
1

我使用Spring @PropertySource註釋根據環境變量加載屬性文件。 (在System variablesof this window在Windows中設置)環境變量不支持UTF-8?

我設置MY_APP = C:\Cliché

現在我@Configuration類還標註有:

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

但是,因爲它似乎解決春季無法加載文件URL /路徑爲:C:\Clich,\config\my.properties

爲什麼?

回答

2

嘗試,在財產來源

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

指定編碼,應該設置系統編碼,然後再開始申請

System.setProperty( 「file.encoding的」, 「UTF-8」) ;

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

+0

但這些設置是用於讀取** **內容的屬性文件嗎? – maxxyme

+0

for @propertysource是, 但是爲了解釋您的系統編碼,您需要設置file.encoding = UTF-8 – kuhajeyan

+0

既不是''編碼=「UTF-8」''作爲''@ PropertySource''屬性,也不添加'' - Dfile.encoding = UTF-8''到我的Tomcat虛擬機參數的工作。 只要我運行一個純Java-config的Spring應用程序,就無處可以設置這個''System.setProperty(「file.encoding」,「UTF-8」);''行來嘗試...... – maxxyme