Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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
Java Spring引导和@ConfigurationProperties_Java_Spring_Spring Boot - Fatal编程技术网

Java Spring引导和@ConfigurationProperties

Java Spring引导和@ConfigurationProperties,java,spring,spring-boot,Java,Spring,Spring Boot,我想(如果可能的话)使用@ConfigurationProperties创建POJO的动态大小列表。请告知这是否可行。我的想法如下(没有省略args构造函数/getter/setter): 属性文件: my.item[0].prop1=a my.item[0].prop2=b my.item[1].prop1=a my.item[1].prop2=b 以及应该填充的bean: @Component @ConfigurationProperties(prefix = "my") public

我想(如果可能的话)使用
@ConfigurationProperties
创建POJO的动态大小列表。请告知这是否可行。我的想法如下(没有省略args构造函数/getter/setter):

属性文件:

my.item[0].prop1=a
my.item[0].prop2=b

my.item[1].prop1=a
my.item[1].prop2=b
以及应该填充的bean:

@Component
@ConfigurationProperties(prefix = "my")
public class ItemsConfig {

    private List<Item> items;

    public static class Item {
        private String prop1;
        private String prop2;
    }
}
@组件
@配置属性(前缀=“我的”)
公共类项目配置{
私人清单项目;
公共静态类项{
私有字符串prop1;
私有字符串prop2;
}
}
不幸的是,当我
@Autowire
项目配置
时,列表总是
null

通过
@configurationproeties
可以实现类似的功能吗

我发现了一种解决方法,它是
BeanFactoryPostProcessor
迭代属性并手动创建所有内容,但代码糟糕:(

请指教

PS:我确实在我的
@配置中使用了
@EnableConfigurationProperties


注意:一旦解决,人们可能会发现,在spring创建具有
@ConfigurationProperties
的组件之前,必须找到并处理
@EnableConfigurationProperties
注释,这很有用。否则,bean将不会被填充。

属性en有一个小问题如果尝试,则应为以下内容:

my.items[0].prop1=a
my.items[0].prop2=b

my.items[1].prop1=a
my.items[1].prop2=b
注意
项目
vs
项目
,要匹配setter名称

是否有那么简单:)让我试试!