Java 将YAML文件中的列表映射到对象列表

Java 将YAML文件中的列表映射到对象列表,java,spring-boot,yaml,Java,Spring Boot,Yaml,我正在尝试将application.yml文件中的list注入到Spring Boot应用程序中的Java对象列表中 我已经看到了其他类似问题的一些答案,但我有不同的输出错误 我的YAML文件 s3tool: buckets: - name: myentity1 accessKey: access secretKey: secret endpoint: endepoint proxyPort: 3128 pr

我正在尝试将application.yml文件中的list注入到Spring Boot应用程序中的Java对象列表中

我已经看到了其他类似问题的一些答案,但我有不同的输出错误

我的YAML文件

s3tool:
   buckets:
     -
      name: myentity1
      accessKey: access
      secretKey: secret
      endpoint: endepoint
      proxyPort: 3128
      proxyHost: gateway-address
     -
      name: myentity2
      accessKey: access
      secretKey: secret
      endpoint: endepoint
      proxyPort: 3128
      proxyHost: gateway-address
我还创建了Bucket类

 public class Bucket {

       private String name;

       private String accessKey;

       private String secretKey;

       private String endpoint;

       private String proxyHost;

       private int proxyPort;

      //getters and setters
  }
以及我的配置类,我在其中将列表注入YAML

    @Configuration
    @EnableConfigurationProperties
    @ConfigurationProperties
    public class S3ClientHelper {

        @Value("${s3tool.buckets}")
        private List<Bucket> buckets;

   //others methods 
   }
我也尝试过使用简单的字符串列表,但也遇到了类似的错误。 我怎么做呢?

试试这个

@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "s3tool")
public class S3ClientHelper {

    private List<Bucket> buckets;

  //others methods 
}
@配置
@EnableConfigurationProperties
@配置属性(前缀=“s3tool”)
公共类S3ClientHelper{
私有列表存储桶;
//其他方法
}

当我尝试此操作时,列表(Bucket)保持为空。是否有用于Bucket的getter和setter?在我的类Bucket中,我有getter和setter,但不用于列表Bucket。请尝试为Bucket添加getter和setter。它应该在bucket类中创建一个构造函数,该构造函数接受每个成员变量。IIRC,Spring希望在这里使用构造函数注入。
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "s3tool")
public class S3ClientHelper {

    private List<Bucket> buckets;

  //others methods 
}