【发布时间】:2016-04-18 17:21:54
【问题描述】:
我正在尝试将我的 application.yml 配置文件中的映射列表注入到我的 Spring Boot 服务中。这是application.yml中的配置:
devoxx:
cfpApis:
-
url: http://cfp.devoxx.be/api/conferences
youtubeChannelId: UCCBVCTuk6uJrN3iFV_3vurg
-
url: http://cfp.devoxx.fr/api/conferences
-
url: http://cfp.devoxx.ma/api/conferences
youtubeChannelId: UC6vfGtsJr5RoBQBcHg24XQw
-
url: http://cfp.devoxx.co.uk/api/conferences
-
url: http://cfp.devoxx.pl/api/conferences
这是我为我服务的财产:
@Value("devoxx.cfpApis")
List<Map<String,String>> cfpApis
但一定有什么问题,因为当我尝试运行我的应用程序时,我得到了以下异常:
java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Map]: no matching editors or conversion strategy found
知道我做错了什么吗?
仅供参考,我正在尝试将 Grails 3 项目迁移到普通 Spring Boot 项目中,并且此配置在 Grails 3 中有效,但 Grails 有自己的 YAML 处理器。
【问题讨论】:
-
到目前为止我还没有使用过
yaml文件,但您通常使用$来引用属性占位符,例如@Value("${devoxx.cfpApis}")。尽管如此,spring documentation 似乎暗示了一种使用@ConfigurationProperties的不同方法。也许this other question 可以提供一些帮助 -
这很好用。谢谢。我将添加一个详细说明此问题的答案
-
干杯,很高兴我能帮上忙 :)
标签: groovy spring-boot yaml