spring boot(18)配置文件值注入-@ConfigurationProperties

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lh87270202/article/details/84102661

1、application.properties配置文件

clockbone.name=zhangsan
clockbone.age=10
clockbone.job=1
#注入Map
clockbone.map.k1=v1
clockbone.map.k2=v2
clockbone.map.c1=32423fsdfsdf
#注入list
clockbone.list=1,2,3,4
//注入type对象
clockbone.type.name=1
clockbone.type.age=2

2、javaBean

对象要实现get set方法

@Component
@ConfigurationProperties(prefix = "clockbone")
@Data
public class TestObj  implements Serializable{
    private static final long serialVersionUID = 7203028940875675470L;
    private String name;
    private String age;
    private String job;
    private Map<String,Object> map;
    private List<Integer> list;
    private Type type;
}
@Data
public class Type implements Serializable{
    private String name;
    private String age;
}

3、结果

TestObj(name=zhangsan, age=10, job=1, map={k1=v1, k2=v2, c1=32423fsdfsdf}, list=[1, 2, 3, 4], type=Type(name=1, age=2))

猜你喜欢

转载自blog.csdn.net/lh87270202/article/details/84102661
今日推荐