属性资源文件的映射

168 阅读1分钟

在日常的开发中,经常涉及到一些通用的资源信息,比如文件路径,端口号等。我们可以将这些信息放到资源文件中。

资源文件

file.imageUserFaceLocation=/workspaces/images/foodie/faces
file.imageServerUrl=http://localhost:8088/foodie/faces

资源文件映射类

@Component
//对应前缀
@ConfigurationProperties(prefix = "file")
//资源文件位置
@PropertySource("classpath:file-upload-prod.properties")
public class FileUpload {

    private String imageUserFaceLocation;
    private String imageServerUrl;

    public String getImageServerUrl() {
        return imageServerUrl;
    }

    public void setImageServerUrl(String imageServerUrl) {
        this.imageServerUrl = imageServerUrl;
    }

    public String getImageUserFaceLocation() {
        return imageUserFaceLocation;
    }

    public void setImageUserFaceLocation(String imageUserFaceLocation) {
        this.imageUserFaceLocation = imageUserFaceLocation;
    }
}