我有这个application.yml文件
messages:
first-journey-messages:
- key: fullName-required
value: This field is required.
- key: fullName-validation
value: Please enter a valid full name.
- key: technical-error
value: Unfortunately we are having technical issues, please try again later.
second-journey-messages:
- key: technical-error
value: "<p class='heading-bold'>Sorry, something went wrong </p><p>We encountered a technical error. Please try again. If you continue to experience difficulties, please call us on 0123456 and an agent will be happy to assist you.</p>"
- key: download-technical-error
value: "<p class='heading-bold'>Sorry, something went wrong </p><p>Unable to download document at this moment. Please try again later.</p>"
third-journey-messages:
- key: home-url
value: /app/home
- key: services-url
value: /app/services我想使用Map注释在下面的@Value对象中阅读上面的配置。
@Value("${messages}")
private Map<String, List<MessageEntry>> messagesMap = new HashMap<>();POJO:MessageEntry
@Data
@AllArgsConstructor
public class MessageEntry implements Serializable {
private String key;
private String value;
}当我试图读取配置时,我得到的是null。
messagesMap.get("second-journey-messages")有人能帮我辨认出我在做什么吗?或者,如何将上面的配置作为Map<String, List<MessageEntry>>类型的对象读取?
注意:我使用的是弹簧引导和lombok。
发布于 2019-07-12 16:13:37
我想这件衣服可以帮你link。尝试更改yml文件中的键值表示法。
https://stackoverflow.com/questions/57010577
复制相似问题