我正在尝试将application.yml文件中的列表注入Spring Boot应用程序中的Java对象列表。
我已经看到了其他类似问题Mapping list in Yaml to list of objects in 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列表,但我也遇到了类似的错误。 我该怎么办?
答案 0 :(得分:0)
试试这个
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "s3tool")
public class S3ClientHelper {
private List<Bucket> buckets;
//others methods
}