SpringBoot里面通过配置文件读取文件夹路径

新建实体类,来对应配置文件里面的属性

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();
}
}


​配置文件夹路径,在参数配置文件里面

dimiapp.uploadpath=C:/eclipse_work/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容