如何从配置层次结构的根部读取 Micronaut 数组属性?
How do I read Micronaut array properties from the root of the configuration hierarchy?
如果我有配置文件
app:
integers:
- 1
- 2
我可以使用 Micronaut 的 ConfigurationProperties 来创建配置 bean:
@ConfigurationProperties("app")
public class AppConfig {
public List<Integer> integers;
}
但是如果整数数组位于配置层次结构的根目录中怎么办:
integers:
- 1
- 2
以下似乎不起作用:
@ConfigurationProperties("")
public class RootConfig {
public List<Integer> integers;
}
@ConfigurationProperties
仅适用于前缀。 ""
不是有效的前缀。
此外,@ConfigurationProperties
仅在您有多个字段时才有意义(可能这就是它无法正常工作的原因)而不是像
这样的字段
integers:
- 1
- 2
在这种情况下,@ConfigurationProperties
有点矫枉过正。像这样使用 @Value
@Value("${integers}")
public List<Integer> integers;
并在yaml中这样声明
integers: 1,2
如果我有配置文件
app:
integers:
- 1
- 2
我可以使用 Micronaut 的 ConfigurationProperties 来创建配置 bean:
@ConfigurationProperties("app")
public class AppConfig {
public List<Integer> integers;
}
但是如果整数数组位于配置层次结构的根目录中怎么办:
integers:
- 1
- 2
以下似乎不起作用:
@ConfigurationProperties("")
public class RootConfig {
public List<Integer> integers;
}
@ConfigurationProperties
仅适用于前缀。 ""
不是有效的前缀。
此外,@ConfigurationProperties
仅在您有多个字段时才有意义(可能这就是它无法正常工作的原因)而不是像
integers:
- 1
- 2
在这种情况下,@ConfigurationProperties
有点矫枉过正。像这样使用 @Value
@Value("${integers}")
public List<Integer> integers;
并在yaml中这样声明
integers: 1,2