本文共 1536 字,大约阅读时间需要 5 分钟。
???Spring Boot?????YAML??????????
?Spring Boot???????????????????????????????????????????????????????YAML???????????
???????????pom.xml?????Spring Boot?????????????????????????????????????
org.springframework.boot spring-boot-configuration-processor
????????????Person??????????????????????????????@Component?@ConfigurationProperties???
@Component@ConfigurationProperties(prefix = "person")public class Person { public String name; public int age; public Date birthday; public Map map; public List list;} @Component????????????Spring?IOC????@ConfigurationProperties(prefix = "person")?????????????????????person????????????????????????Person??????@Autowired????????????????????????
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;@SpringBootTestpublic class DemoApplicationTests { @Autowired private Person person; @Test void contextLoads() { System.out.println("?????" + person); }} ????????????????????????????????????????
Person{name='zhangsan', age=20, birthday=Sun Nov 01 00:00:00 CST 2020, map={k1=v1, k2=v2}, list=[aaa, bbb, ccc]} ?resources????????applications.yml????????
person: name: zhangsan age: 20 birthday: 2020/11/1 map: k1: v1 k2: v2 list: - aaa - bbb - ccc
??????????????????????????????Person????????????????????????????????????????????
转载地址:http://yayg.baihongyu.com/