【发布时间】:2019-09-06 23:27:59
【问题描述】:
我已通过以下方式从 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 中所述)
也没有
app:
map:
"[Countries]": countries.xslx
"[CurrencyRates]": rates.xlsx
(如https://stackoverflow.com/a/51751123/2566304 建议的那样)
有效 - 我不断收到消息“自动装配依赖项注入失败;嵌套异常是 java.lang.IllegalArgumentException: 无法解析占位符'
同时这也有效:
@Value("#{{Countries: 'countries.xlsx', CurrencyRates: 'rates.xlsx'}}")
private Map<String, String> indexesMap = new HashMap<>();
但我想将属性外部化
【问题讨论】:
标签: spring spring-boot dependency-injection yaml spring-annotations