spring boot: 查看ApplicationContext中有哪些Bean
生活随笔
收集整理的這篇文章主要介紹了
spring boot: 查看ApplicationContext中有哪些Bean
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
- 想查看ApplicationContext中類型為MyClass.class的Bean有哪些
方法
System.out.println(new Gson().toJson(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, MyClass.class)));例子
@Component public class TemplateEngineBeanPrinter implements ApplicationContextAware {private ApplicationContext applicationContext;@Overridepublic void setApplicationContext(ApplicationContext applicationContext) {this.applicationContext = applicationContext;}@PostConstructpublic void a() {System.out.println("=============TemplateEngine Beans=============");System.out.println(new Gson().toJson(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, TemplateEngine.class)));} }執行結果:
=============TemplateEngine Beans============= ["htmlTemplateEngine","jsonTemplateEngine","rssTemplateEngine","templateEngine"]參考
https://blog.csdn.net/weixin_33910385/article/details/89688284
總結
以上是生活随笔為你收集整理的spring boot: 查看ApplicationContext中有哪些Bean的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小麦茶的功效与作用、禁忌和食用方法
- 下一篇: The jar file has no