我通过以下方式从 Spring Boot 应用程序中的某些 .yaml 读取的地图中注入了属性:
@Value("#{${app.map}}")
private Map<String, String> indexesMap = new HashMap<>();
但两者都没有
app:
map: {Countries: 'countries.xlsx', CurrencyRates: 'rates.xlsx'}
//note values in single quotes
nor
app:
map: {Countries: "countries.xlsx", CurrencyRates: "rates.xlsx"}
(如所解释的https://www.baeldung.com/spring-value-annotation https://www.baeldung.com/spring-value-annotation)
nor
app:
map:
"[Countries]": countries.xslx
"[CurrencyRates]": rates.xlsx
(如建议的https://stackoverflow.com/a/51751123/2566304 https://stackoverflow.com/a/51751123/2566304)
有效 - 我不断收到消息“自动装配依赖项注入失败;嵌套异常是 java.lang.IllegalArgumentException:无法解析占位符'
同时这也有效:
@Value("#{{Countries: 'countries.xlsx', CurrencyRates: 'rates.xlsx'}}")
private Map<String, String> indexesMap = new HashMap<>();
但我想将属性外部化