@PropertySource絕對路徑(java.io.FileNotFoundException問題解決)

經常使用@PropertySource 來指定配置文件,然後@value獲取配置參數:

1 @Component
2 @PropertySource(value= {"classpath:rules.yml"})
3 @ConfigurationProperties(prefix = "busi-udid-mapper")

 

默認,配置文件都是指定classpath下的文件路徑,如果使用絕對路徑(操作系統下某個配置文件路徑),請使用如下方式:

1 @Component
2 @PropertySource(value= {"file:${rule.fullpath}"})
3 @ConfigurationProperties(prefix = "busi-udid-mapper")

這裏的rule.funnpath是在系統配置文件中變量化的參數

 

 

參考:

http://www.voidcn.com/article/p-scladotq-bva.html

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章