亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring: @PropertySource注解如何能夠引入非classpath下的資源文件?

Spring: @PropertySource注解如何能夠引入非classpath下的資源文件?

楊__羊羊 2019-03-01 10:27:09
網上的資料一般在使用@PropertySource的時候,都喜歡用@PropertySource("classpath:/document.properties")這種形式 現在我把資源文件的路徑放在application.properties里 config.path=/home/myservice/config.properties 然后在java源碼里: @PropertySource(value = {"${config.path}"}, encoding="utf-8") public class MyConfig { @Value("${myconfig.index}") private String index; public String getIndex() { return index; } } 但是出錯: Caused by: java.io.FileNotFoundException: class path resource [home/myservice/config.properties] cannot be opened because it does not exist
查看完整描述

3 回答

?
慕后森

TA貢獻1802條經驗 獲得超5個贊

配置的路徑要相對于class文件的根目錄,class path

查看完整回答
反對 回復 2019-03-01
?
天涯盡頭無女友

TA貢獻1831條經驗 獲得超9個贊

使用:@PropertySource(value = "file:${config.path}",ignoreResourceNotFound = true)
不要忘記@Configuration注解

查看完整回答
反對 回復 2019-03-01
  • 3 回答
  • 0 關注
  • 964 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號