//获取springboot所有加载的bean
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
};
}
spring boot获取容器所有初始化的bean
最新推荐文章于 2026-04-18 01:35:01 发布
本文介绍了一种在SpringBoot应用中查看所有加载Bean的方法,通过实现CommandLineRunner接口并在其run方法中打印ApplicationContext中所有Bean的名称,帮助开发者了解SpringBoot如何管理和加载Bean。

417

被折叠的 条评论
为什么被折叠?



