public class Clazz {
private String str; // 字符串
private List<String> strings; // 字符串列表
private List<User> users; // 对象列表,脑补User中包含name和age两个属性
}
application.yml
custom:
str: ABCD
strings: ABC, DEF, GHI
users:
- { name: zhangsan, age: 20 }
- { name: lisi, age: 22 }
@Component
@ConfigurationProperties("custom") // 或(prefix = "custom")
public class Clazz {
private String str; // 字符串
private List<String> strings; // 字符串列表
private List<User> users; // 对象列表,脑补User中包含name和age两个属性
}
configuration-processor
依赖
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
本文地址:https://blog.csdn.net/wang4721/article/details/107679721
如对本文有疑问, 点击进行留言回复!!
网友评论