栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

三、SpringBoot配置文件

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

三、SpringBoot配置文件

三、SpringBoot配置文件 1、yaml配置文件
  • YAML是"YAML ain’t Markup language" 不是标记语言的标记语言
  • 非常适合做以数据为中心的配置文件
  • 基本语法
    • key: value : key-value 之间有空格
    • 大小写敏感
    • 使用缩进表示层级关系
    • 缩进的空格数不重要,只要相同层级的元素左对齐即可
    • # 表示注释
    • 字符串无需添加引号,如果要添加,"" 双引号不会转义,’'单引号会转义
2、yaml使用的示例
  • Person.java

    @Component//加入到容器中去
    @ConfigurationProperties(prefix = "person")
    @Data
    @ToString
    public class Person {
        private String userName;
        private Boolean boss;
        private Date birth;
        private Integer age;
        private Pet pet;
        private String[] interests;
        private List animal;
        private Map score;
        private Set salarys;
        private Map> allPets;
    }
    
  • Pet.java

    @Data
    @ToString
    public class Pet {
        private String name;
        private Double weight;
    }
    
  • application.yaml示例

    person:
      userName: 张三
      boss: true
      birth: 2020/10/31
      age: 1
      pet:
        name: 花花
        weight: 37
      interests:
        - 篮球
        - 游泳
      animal: [jerry,tom]
      score:
        english: 78
        math: 79
      salarys:
        - 9999
        - 8888
      allPets:
        sick:
          - {name: tom,weight: 34}
          - {name: lisi,weight: 56}
    #      - pet:
    #          name: 阿猫
    #          weight: 23 错误的
        health: [{name: jerry,weight: 55}]
    
3、编写提示以及去除无用插件
  • 只需要在pom.xml文件中配置以下内容即可

            
                org.springframework.boot
                spring-boot-configuration-processor
                true
            
        
        
        
            
    
                
                    org.apache.maven.plugins
                    maven-compiler-plugin
                    
                        none
                    
                
            
        
    
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/424513.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号