1.创建一个file.properties文件
file.imageLocationPath=d:\\myFile\\images
file.imageServerUrl=http://localhost:8088/server
2.创建一个资源类
@Component
@ConfigurationProperties(prefix = "file")
@PropertySource("classpath:file.properties")
public class FileUpload {
private String imageLocationPath;
private String imageServerUrl;
public String getImageServerUrl() {
return imageServerUrl;
}
public void setImageServerUrl(String imageServerUrl) {
this.imageServerUrl = imageServerUrl;
}
public String getImageUserFaceLocation() {
return imageUserFaceLocation;
}
public void setImageLocationPath(String imageLocationPath) {
this.imageLocationPath= imageLocationPath;
}
}
3.使用
@Autowired
private FileUpload fileUpload;
public void test(){
String fileSpace = fileUpload.getImageLocationPath();
}