gpt4 book ai didi

java - 从 application.yml 读取配置到 POJO 列表的 Map

转载 作者:行者123 更新时间:2023-12-02 03:07:59 35 4
gpt4 key购买 nike

我有这个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>> 类型的对象?

注意:我将spring bootlombok一起使用

最佳答案

我认为这个答案可以帮助你link 。尝试更改 yml 文件中的键、值表示法。

关于java - 从 application.yml 读取配置到 POJO 列表的 Map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57010577/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com