nacos配置yaml文件,读取格式为Map<String, List<String>>数据: 1、当数据不含有中文字符时,格式如下:
test: map: key1: - value1 - value2 key2: - value3 - value4 key3: - value52、当数据含有中文字符或者其他特殊字符时,可参考如下:
test: map: "[中文字符1]": - 键值1 - 键值2 - 键值7 "[中文字符2]": - 键值3 - 键值4 "[中文字符3]": - 键值5 - 键值6nacos配置参考:
spring: application: name: serve-query cloud: nacos: discovery: server-addr: ${NACOS-SERVER:http://127.0.0.1:8848} namespace: ${NACOS-NAMESPACE:} config: server-addr: ${NACOS-SERVER:http://127.0.0.1:8848} namespace: ${NACOS-NAMESPACE:} file-extension: yaml shared-configs[0]: data-id: serve-query.yaml group: DEFAULT_GROUP refresh: true shared-configs[1]: data-id: test-map.yaml group: DEFAULT_GROUP refresh: trueSpringboot使用@ConfigurationProperties注解获取代码参考如下:
import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.stereotype.Component; import java.util.LinkedHashMap; import java.util.List; /** * Map读取测试 * * @author 星空流年 * @date 2022/10/27 */ @Data @Component @ConfigurationProperties(prefix = "test") @RefreshScope public class MapTest { private LinkedHashMap<String, List<String>> map = new LinkedHashMap<>(); }
测试结果如下:
标签:Map,List,nacos,NACOS,yaml,键值,import From: https://www.cnblogs.com/cndarren/p/16833526.html