[英]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.