SpringBoot里面通過配置文件讀取文件夾路徑

新建實(shí)體類,來對應(yīng)配置文件里面的屬性

package com.hzdimi.loan.web.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = “dimiapp”)
public class AppSettings {
private String uploadpath;
public String getUploadpath() {
return uploadpath;
}
public void setUploadpath(String uploadpath) {
this.uploadpath = uploadpath;
}
}

在SpringBoot啟動里面配置

package com.hzdimi.loan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import com.hzdimi.loan.service.system.SystemService;
import com.hzdimi.loan.utils.SpringContextUtil;
import com.hzdimi.loan.web.config.AppSettings;
@SpringBootApplication
@EnableConfigurationProperties({AppSettings.class}) ? ? ? ? //此處
public class LoanAppRun {
public static void main(String[] args) throws Exception {
SpringApplication.run(new Object[] { LoanAppRun.class }, args);
SystemService systemService = (SystemService) SpringContextUtil.getBean(“systemService”);
systemService.loadDicMap();
}
}


?配置文件夾路徑,在參數(shù)配置文件里面

dimiapp.uploadpath=C:/eclipse_work/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容