当前位置:   article > 正文

nacos yaml 自定义 map、list 配置_nacos配置list

nacos配置list

前言

nacos yaml map配置
yaml map配置key使用数字
yaml map嵌套map配置

启动类添加注解


@ConfigurationPropertiesScan("com.1111.test.app.1111.config")
  • 1
  • 2

list配置

yaml

mqtt:
  topic:
    # 应用模拟器
    application:
      # 应用监听【订阅】
      listeners: 
        # 设备属性上报
        - name: propertiesReport
          value: oc/devices/%s/%s/properties/report
          show: true
        # 设备消息上报
        - name: messagesUp
          value: oc/devices/%s/%s/messages/up
          show: false
        # 设备命令回复
        - name: commandsResponse
          value: oc/devices/%s/%s/commands/response
          show: false
        # 设备事件上报
        - name: eventsUp
          value: oc/devices/%s/%s/events/up
          show: false
      # 应用下发【发布】  
      down:
        # 平台消息下发
        - name: messagesDown
          value: oc/devices/%s/%s/messages/down
          show: false
        # 平台命令下发
        - name: commandsDown
          value: oc/devices/%s/%s/commands/down
          show: false
        # 平台事件下发
        - name: eventsDown
          value: oc/devices/%s/%s/events/down
          show: true
    # 设备模拟器
    simulator:
      # 设备监听【订阅】
      listeners: 
        # 平台消息下发
        - name: messagesDown
          value: oc/devices/%s/%s/messages/down
          show: false
        # 平台事件下发
        - name: eventsDown
          value: oc/devices/%s/%s/events/down
          show: true
        # 平台消息下发
        - name: commandsDown
          value: oc/devices/%s/%s/commands/down
          show: false
      # 设备上报【发布】  
      up:
        # 设备消息上报
        - name: messageUp
          value: oc/devices/%s/%s/messages/up
          show: false
        # 设备命令回复
        - name: commandsResponse
          value: oc/devices/%s/%s/commands/response
          show: false
        # 设备属性上报
        - name: propertiesReport
          value: oc/devices/%s/%s/properties/report
          show: true
        # 设备事件上报
        - name: eventsUp
          value: oc/devices/%s/%s/events/up
          show: false
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70

java


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Wang
 */
@Component
@ConfigurationProperties(prefix = "mqtt.topic")
@Data
public class MqttTopicConfig {

    private Application application;
    private Simulator simulator;

    @Data
    public static class Application {
        private List<Item> listeners;
        private List<Item> down;
    }

    @Data
    public static class Simulator {
        private List<Item> listeners;
        private List<Item> up;
    }

    @Data
    public static class Item {
        private String name;
        private String value;
        private Boolean show;
    }

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

map配置

yaml


1111:
  maintenance:
    pwc:
      en:
        '1': Engine oil
        '2': 2222
      jp:
        '1': Engine oil
        '2': 2222

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

java


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.Map;

/**
 * @author Wang
 * @Date 2022/12/1
 */
@Data
@Component
@RefreshScope
@ConfigurationProperties(prefix = "1111.maintenance")
public class MaintenanceItemConfig {

    private Map<String, Map<String, String>> pwc;
    private Map<String, Map<String, String>> sxs;

    @Data
    public static class Item {
        private String index;
        private String value;
    }

}



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

map 嵌套 list

yaml

1111:
  maintenance:
    item:
      en:
        - index: 1
          name: Engine oil
          type: 1
        - index: 2
          name: Air cleaner
          type: 2
        - index: 3
          name: Brake fluid
          type: 2
        - index: 4
          name: Brake pads
          type: 2
        - index: 5
          name: Coolant
          type: 2
        - index: 6
          name: Gearcase oil
          type: 2
        - index: 7
          name: Oil change
          type: 2
        - index: 8
          name: Oil filter
          type: 1,2
        - index: 9
          name: Tire change
          type: 2
        - index: 10
          name: Tire Pressure
          type: 2
        - index: 11
          name: Wheel parts
          type: 2
        - index: 12
          name: Regular inspection
          type: 2
        - index: 13
          name: Handlebar pivot lubrication
          type: 1
        - index: 14
          name: Joint lubrication
          type: 1
        - index: 15
          name: Spark plugs
          type: 1
        - index: 16
          name: Regular points inspection
          type: 1
        - index: 17
          name: Other
          type: 1,2
      #日语先用英语代替
      jp:
        - index: 1
          name: Engine oil
          type: 1
        - index: 2
          name: Air cleaner
          type: 2
        - index: 3
          name: Brake fluid
          type: 2
        - index: 4
          name: Brake pads
          type: 2
        - index: 5
          name: Coolant
          type: 2
        - index: 6
          name: Gearcase oil
          type: 2
        - index: 7
          name: Oil change
          type: 2
        - index: 8
          name: Oil filter
          type: 1,2
        - index: 9
          name: Tire change
          type: 2
        - index: 10
          name: Tire Pressure
          type: 2
        - index: 11
          name: Wheel parts
          type: 2
        - index: 12
          name: Regular inspection
          type: 2
        - index: 13
          name: Handlebar pivot lubrication
          type: 1
        - index: 14
          name: Joint lubrication
          type: 1
        - index: 15
          name: Spark plugs
          type: 1
        - index: 16
          name: Regular points inspection
          type: 1
        - index: 17
          name: Other
          type: 1,2    

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109

java

package com.1111.test.app.1111.config;

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.Map;

@Data
@Component
@RefreshScope
@ConfigurationProperties(prefix = "1111.maintenance")
public class MaintenanceItemConfig {

    private Map<String, List<MaintenanceItem>> item;

    @Data
    public static class MaintenanceItem {
        private String index;
        private String name;
        private String type;
    }


}


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/594515
推荐阅读
相关标签
  

闽ICP备14008679号