首页 > 其他分享 >springboot nacos使用yaml配置list方式

springboot nacos使用yaml配置list方式

时间:2023-11-07 14:34:40浏览次数:31  
标签:springboot list1 demo app xiaohong list nacos private list2

方式一

配置项:
app:
  demo:
    list1: xiaohong, xiaoming
    list2: >
      xiaohong,
      xiaoming

list1和list2看起来是2种风格,其实都是同一种写法,以逗号分隔

java代码:
@Data
@Component
public class AppConfig1 {

@Value("${app.demo.list1}")
private List<String> list1;

@Value("${app.demo.list1}")
private String[] array1;

@Value("${app.demo.list2}")
private List<String> list2;
}

执行结果:可以正常获取到

 

方式二

配置项:
app:
  demo:
    list3:
      - xiaohong
      - xiaoming
java代码:
使用方式一的java代码就不行了,换一种方式
@Data
@Component
@ConfigurationProperties(prefix = "app.demo")
public class AppConfig2 {

private List<String> list3;
}

执行结果:可以正常获取

 

标签:springboot,list1,demo,app,xiaohong,list,nacos,private,list2
From: https://www.cnblogs.com/myf008/p/17814912.html

相关文章

  • SpringBoot获取配置文件-@Value、@ConfigurationProperties方式
    配置文件yml#phantomjs的位置地址phantomjs:binPath:windows:binPath-winlinux:binPath-linuxjsPath:windows:jsPath-winlinux:jsPath-linuximagePath:windows:imagePath-winlinux:imagePath-linuxphantomjs2:binPath2:I‘......
  • js 数组按指定字段转map-list结构
    js数组按指定字段转map-list结构背景介绍在开发过程中经常会出现接口返回整个数组,我们需要将数组进行二次处理,如下格式按照不同功能模块(type)进行数据拆分原始数据constlist=[{"type":"red","id":1,"name":"a","count":1}, {"type":"red","......
  • .NET(C#) LinkedList、Queue<T>和Stack<T>的使用
    本文主要介绍.NET(C#)中,LinkedList链表、Queue<T>队列和Stack<T>堆栈的使用,以及相关的示例代码。1、LinkedList(链表)链表中元素存储内存中是不连续分配,每个元素都有记录前后节点,节点值可以重复,不能通过下标访问,泛型的使用保证类型安全,可以避免装箱拆箱,找元素就只能遍历,查找不方......
  • SpringBoot 单元测试
    1、什么是单元测试?单元测试(UnitTesting)是一种软件测试方法,用于验证和确认代码中的各个单元(通常是函数、方法或类)是否按照预期工作。单元测试旨在检测代码中的小部分,以确保其功能的正确性。2、单元测试有哪些好处?在单元测试中使用模拟对象来替代实际的数据库访问操作,不会实际修改数......
  • springboot mybatis-plus 登录接口
    下面是使用SpringBoot和MyBatis-Plus实现登录接口的示例代码:添加依赖在pom.xml文件中添加以下依赖:<dependencies><!--SpringBoot--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</a......
  • springboot+mybatis-plus批量删除
    可以使用Mybatis-Plus提供的deleteBatchIds方法来实现批量删除。示例代码:@AutowiredprivateMybatisPlusMappermybatisPlusMapper;publicvoiddeleteBatch(List<Long>ids){mybatisPlusMapper.deleteBatchIds(ids);}其中,MybatisPlusMapper是你的Mapper接口,继承了BaseMa......
  • 如何在idea中创建一个SpringBoot项目
    在IntelliJIDEA中创建一个SpringBoot项目非常简单。下面是一步一步的指南:打开IntelliJIDEA:启动IntelliJIDEA,确保你已经安装并配置好Java开发环境。创建新项目:如果你在IDEA的欢迎界面,点击"CreateNewProject"。如果你已经有一个项目打开,可以通过选择"File"->"New......
  • C#学习之ListBox,ComboBox,CheckListBox
    ListBox(文本列表)常用属性:Items:描述:ListBox中的项列表。默认值:空用法:可以使用Add(),AddRange(),Insert(),Remove(),Clear(),等方法来对Items集合进行管理。SelectedIndex:描述:ListBox中当前选择项的索引。默认值:-1(表示没有选中项)用法:通过设置或读取该属......
  • Java:SpringBoot实现JDK动态代理和CGLIB动态代理
    (目录)需要代理的对象//接口publicinterfacePayService{voidpay();}//实现publicclassAliPayServiceimplementsPayService{@Overridepublicvoidpay(){System.out.println("AliPayService");}}1.JDK动态代理在JDK动态代......
  • Docker下安装nacos
    1、拉取镜像dockerpullnacos/nacos-server2、挂载目录,用于映射到容器,目录按自己的情况创建dockervolumecreatenacos_testmkdir-p/var/lib/docker/volumes/nacos_test/logs/                     #新建logs目录mkdir-p/var/lib/docker/v......