繁体   English   中英

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

[英]Mapping List in YAML file to List of objects

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

我已经看到了对其他类似问题的一些答案,Yaml中的列表映射到Spring Boot中的对象列表,但是我有不同的输出错误。

我的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 
   }

当Spring Boot开始执行时,出现以下错误:

  Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 's3tool.buckets' in value "${s3tool.buckets}"

我也尝试过使用String的简单列表,但是我也遇到了类似的错误。 我该怎么做?

尝试这个

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

    private List<Bucket> buckets;

  //others methods 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM