1.创建三个pojo
2.Person引用了Child和Cat
@Component 将普通的类实例化到spring容器中
@Date lombok的功能用,智能生成set 和get
lombok的范围是provider 在编译和测试的时候有效,运行的时候无效,不会被打包
@NoArgsContructor 无参数构造函数
@AllArgsConstrutor 全参数构造函数
@ConfigurationPropertis(prefix="person") 当person类被实例化的时候,会将配置中以person开头的数据注入person对象
2.在application.yml中配置属性
语法
1.key: value,冒号后面有空格
2.数组用 - 属性,一个引用一个-
3.map 需要制定key
3.在主函数中输出person对象
var app=SpringApplication.run(this.getClass,args);
var person=app.getBean("person");
System.out.println(person);
4.查看输出结果
Person(id=122, name=张三, childList=[Child(id=123, name=小花), Child(id=124, name=小草)], cats={c1=Cat(id=125, name=花猫), c2=Cat(id=126, name=懒猫)})
完结,撒花