映射到CONFIGS枚举类型
问题描述:
#Reports
reports:
PnLReport:
reportId: 10
path: \\\\pathto\\PnLreport\\
BalanceSheetReport:
reportId: 11
path: \\\\pathto\\balancesheet\\
schedule-10:
description: Deliver pnl reports
report: 10
format: PDF, XLS
我在我的申请Spring Boot
在application.yml
文件中定义的上述性质。映射到CONFIGS枚举类型
-
我怎么能映射
repordId
和path
性质的enum
例如,对于每一个报告类型。例如:public enum ReportType{ PNL(...) BALANCE(...); private final String reportId; private final String path; private ReportType(String reportId, String path) { this.identifier = identifier; }
接下来,我想下
schedule-10
属性将reportId
report: 10
之间的映射来推导一个FileService
类例如路径,这样我可以看,如果路径中存在的文件。我怎样才能做这个映射?这是我能想到的唯一方法,我的要求是否有更好的方法呢?
答
我不知道我会建议使用此枚举,因为你正在寻找的是更就像一个可配置的属性实例。也许考虑使用一个简单的类来读取它的两个实例?
public class ReportType {
private Integer reportId;
private String path;
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public void getReportId() {
return reportId;
}
public Integer setReportId(Integer reportId) {
this.reportId = reportId;
}
}
@Component
@ConfigurationProperties(prefix = "reports")
public class ReportTypes {
public ReportType PlnReport;
public ReportType BalanceSheetReport;
}
该问题与如何将配置设置解析为类而不是原语有关。 – Almund