springboot容器配置管理

spring两大特性之一 IOC 容器化管理
spring 在将组件配置通过容器xml文件的方式配置使用bean标签吧bean注入到spring容器中,让spring进行对bean的管理,
如:

  • XML配置:

  • 两个bean

Springboot注解方式注入
Springboot使用配置类在改类上加上@Configration注解,让springboot将该类识别为配置类
通过方法上加入@Bean注解 就可以在容器中注入改bean

获取容器对象

打印结果

posted @ 2022-06-22 15:28  思远宁致  阅读(135)  评论(0)    收藏  举报