Springboot @ConfigurationProperties 到 Map 的 Map 或(嵌套 Map/MultiKeyMap)
我试图通过 yaml 文件保留域上的一些业务配置。
yml
配置文件的结构:
bank:
accountType1:
debit:
- Product1
- Product2
hybrid:
- ProductX
- ProductY
accountType2:
debit:
- Product1
- Product2
- Product3
hybrid:
- ProductX
- ProductY
- ProductZ
我在域上有以下枚举。
enum AccountType{ ACCOUNT_TYPE1, ACCOUNT_TYPE2}
enum Feature{ DEBIT, HYBRID}
enum Products { Product1, Product2, Product3, ProductX, ProductY, ProductZ }
我想寻求帮助以将这些业务配置作为 MultikeyMap 或嵌套映射,但使用枚举作为键。例如:
Map<AccountType, Map<Feature, List<Products>>
基本上我希望配置执行以下查找:
if AccountType = accountType1 & Feature = debit, then return [Product1,Product2]
我找不到通过配置文件优雅地执行此操作的方法,因为它总是初始化为 null
@ConfigurationProperties(prefix="bank")
public class ProductResolver {
Map<AccountType, Map<Feature, List<Products>> configMap
// NestedMap, Apache MultiKeymap or something similar either should be ok for me
}
任何专家,请指导我吗?
I'm trying to retain a few business configs on the domain through yaml
file.
Structure of yml
config file:
bank:
accountType1:
debit:
- Product1
- Product2
hybrid:
- ProductX
- ProductY
accountType2:
debit:
- Product1
- Product2
- Product3
hybrid:
- ProductX
- ProductY
- ProductZ
I have the below enums for on the domain.
enum AccountType{ ACCOUNT_TYPE1, ACCOUNT_TYPE2}
enum Feature{ DEBIT, HYBRID}
enum Products { Product1, Product2, Product3, ProductX, ProductY, ProductZ }
I would like to seek help to get these business configs as a MultikeyMap, or a nested map, but using enums as keys. For eg:
Map<AccountType, Map<Feature, List<Products>>
Basically I would like the config to perform the following lookup:
if AccountType = accountType1 & Feature = debit, then return [Product1,Product2]
I couldn't find a way to do this elegantly via config files, as it always initialises to null
@ConfigurationProperties(prefix="bank")
public class ProductResolver {
Map<AccountType, Map<Feature, List<Products>> configMap
// NestedMap, Apache MultiKeymap or something similar either should be ok for me
}
Any experts, please could you guide me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以稍微更改映射,如下所示:
那么下面的配置实际上对我来说效果很好:
If you can slightly change you mappings, like this:
Then below config actually worked for me just fine: