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配置 : YAML (简介+语法+配置文件值注入)+报错提示Spring Boot Configuration Annotation Processor not
-
Spring Boot配置与配置文件属性值注入
-
Spring boot配置文件值注入
-
结合SpEL使用@Value-基于配置文件或非配置的文件的值注入-Spring Boot
-
spring boot(18)配置文件值注入[email protected]
-
Spring Boot配置文件值的注入方式
-
Spring Boot之配置文件值注入(@ConfigurationProperties)
-
Spring Boot配置 : YAML (简介+语法+配置文件值注入)+报错提示Spring Boot Configuration Annotation Processor not
-
Spring Boot 配置文件值注入
-
Spring Boot 通过配置文件注入自定义属性值时需要注意 yes 和 no