打印所有加载的Spring bean [英] Print all the Spring beans that are loaded

查看:361
本文介绍了打印所有加载的Spring bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法打印启动时加载的所有spring bean?我使用的是Spring 2.0。

Is there a way to print all the spring beans that are loaded on startup?I am using Spring 2.0.

推荐答案

是的,得到 ApplicationContext 并调用 .getBeanDefinitionNames()

您可以通过以下方式获取上下文:

You can get the context by:


  • 实施 ApplicationContextAware

  • 注入 / @Autowired (2.5之后)

  • 使用 WebApplicationContextUtils.getRequiredWebApplicationContext(..)

  • implementing ApplicationContextAware
  • injecting it with @Inject / @Autowired (after 2.5)
  • use WebApplicationContextUtils.getRequiredWebApplicationContext(..)

相关:您还可以通过注册 BeanPostprocessor bean来检测每个bean的注册。每个bean都会收到通知。

Related: You can also detect each bean's registration by registering a BeanPostprocessor bean. It will be notified for each bean.

这篇关于打印所有加载的Spring bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆