欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring boot(18)配置文件值注入[email protected]

程序员文章站 2022-05-01 23:07:44
...

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))
相关标签: spring boot