springboot配置文件详解

springboot配置文件详解

​ 在之前的项目开发中,我们可以使用xml,properties进行相关的配置,这种配置方式比较简单,但是在应对复杂的商业需求下,多环境和编程化的配置无法得到满足,因此springboot为我们提供了YAML的配置方式丰富功能和简化开发。

1、Properties配置详解

​ 通常情况下,我们可以使用properties文件进行相关的配置。

​ (1)在resources目录下创建application.properties

person.name=zhangsan
person.age=12
person.gender=男
person.desc=my name is ${person.name},my age is ${person.age}

​ (2)创建对应的实体类对象

@Component
public class Person {
   
   
    @Value("${person.name}")
    private String name;
    @Value("${person.age}")
    private int age;
    private String sex;
    @Value("${person.desc}")
    private String desc;

    public Person() {
   
   
    }

    public Person(String name, int age, String sex) {
   
   
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    @Override
    public 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值