springboot中属性map,list的注入

1 yml文件格式

1-1 注入list

appconfigs:
  #初始化list
  strList:
    - star
    - moon
    - sun

1-2 初始化map

appconfigs:
  #初始化map
  strMap: {name: 'star',age: 25}

1-3 map 中有list

appconfigs:
  #初始化map<String,List<Object>>
  mapList:
    name:
      - star
      - star1
      - star2
    age:
      - 25
      - 18
      - 20

1-4 list中有 map

listMap:
    - {appId: '1234',token: '2234'}
    - {appId: '3234',token: '4234'}

或者

projects:
  list:
    - name: project_one
      projectId: project_id_111111
    - name: project_two
      projectId: project_id_222222
    - name: your_name
      projectId: your_id

1-5 注入复杂对象

image

image

posted @ 2021-12-16 15:53  姚狗蛋  阅读(604)  评论(0编辑  收藏  举报