
资源文件:file-upload-dev.properties
file.imageUserFaceLocation=D:\\Environment\\apache-tomcat-9.0.46\\webapps\\foodie\\faces
类映射
package com.shiers.resource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
/**
* Demo class
*
* @author shierS
* @date 2021/6/6
*/
@Component //组件标识,被spring扫描
@ConfigurationProperties(prefix = "file") //读取配置文件 prefix 指定属性的前缀
@PropertySource("classpath:file-upload-dev.properties") //配置对应配置文件的地址
public class FileUpload {
private String imageUserFaceLocation;
public String getImageUserFaceLocation() {
return imageUserFaceLocation;
}
public void setImageUserFaceLocation(String imageUserFaceLocation) {
this.imageUserFaceLocation = imageUserFaceLocation;
}
}
使用
@Autowired
private FileUpload fileUpload;
String fileSpace = fileUpload.getImageUserFaceLocation();