Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 根据属性文件中的值声明枚举_Spring_Spring Boot_Enums - Fatal编程技术网

Spring 根据属性文件中的值声明枚举

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

我有如下属性文件(application.yml):

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;
}