Java --- springboot2的配置文件与配置提示

目录

一、配置文件

1.1、yaml 

1.2、基本语法 

1.3、数据类型 

1.4、案例测试

二、配置提示


一、配置文件

1.1、yaml 

YAML是“YAML Ain't Markup Language”的递归缩写。非常适合用来做以数据为中心的配置文件。

1.2、基本语法 

1、key:value;kv之间有空格。

2、大小写敏感。

3、使用缩进表示层级关系。

4、缩进不允许使用tab,只允许空格。

5、缩进的空格数不重要,只要相同层级的元素左对齐就行。

6、'#'表示注释。

7、字符串无需加引号,如果要加,"与"表示字符串内容会被转义/不转义。

1.3、数据类型 

1、字面量:单个的、不可再分的值。

2、对象:键值对的集合。

3、数组:一组按次序排列的值。

1.4、案例测试

@Data
@ToString
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
    private String userName;
    private Boolean boss;
    private Date birth;
    private Integer age;
    private Pet pet;
    private String[] interests;
    private List<String> animal;
    private Map<String, Object> score;
    private Set<Double> salarys;
    private Map<String, List<Pet>> allPets;
}
@Data
@ToString
public class Pet {
    private String name;
    private Double weight;
}
person:
  userName: laomo
  boss: true
  birth: 2000/12/12
  age: 18
#interests: [卖鱼,送鱼]
  interests:
    - 卖鱼
    - 送鱼
  animal: [草鱼,鲤鱼]
#score:
#math: 80
  score: {math:80}
  salarys:
    - 5000.00
    - 8900.00
  pet:
    name: 金龙鱼
    weight: 3.00
  allPets:
    sick:
      - {name: 金龙鱼,weight: 3.00}
      - name: 草鱼
        weight: 4.00
    health:
      - {name: 银龙鱼,weight: 3.00}

二、配置提示

<!--配置提示-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
<!--打包排除-->
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-configuration-processor</artifactId>
                        </exclude>
                    </excludes>
                </configuration>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鸭鸭老板

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值