Spring 根据属性文件中的值声明枚举
我有如下属性文件(application.yml):Spring 根据属性文件中的值声明枚举,spring,spring-boot,enums,Spring,Spring Boot,Enums,我有如下属性文件(application.yml): userID: limitedAttempts: - bins: - "123456" attempts: 2 bookType: ALPHA - bins: - "789012" attempts: 2 bookType: NHANAM 和属性的类别: @Component @ConfigurationProperties(prefix = "userID") @RefreshScope public
userID:
limitedAttempts:
-
bins:
- "123456"
attempts: 2
bookType: ALPHA
-
bins:
- "789012"
attempts: 2
bookType: NHANAM
和属性的类别:
@Component
@ConfigurationProperties(prefix = "userID")
@RefreshScope
public class UserIDProperties {
private List<LimitedAttempt> limitedAttempts = new ArrayList<>();
...
public static class LimitedAttempt{
private List<String> bins = new ArrayList<>();
private int attempts;
private BookType bookType;
...
}
}
在重建项目中,图书类型将为:ALPHA、NHANAM、FIRSTNEW。
我可以这样做吗
*注意:我可以将BookType声明为java
public enum BookType{
ALPHA,
NHANAM;
}
但它不是动态的,因为我使用concur,所以我不想用java代码进行更新。
感谢您的帮助。既然您可以将
BookType
定义为一个类,为什么还要使用enum?我希望避免向当前移动版本中无法处理的移动设备发送数据。目前,移动设备只能处理ALPHA和NHANAM,我们应该确保在他们处理之前不会发送新的图书类型。@LocLe你解决了这个问题吗?
public enum BookType{
ALPHA,
NHANAM;
}