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

查看:34
本文介绍了打印所有加载的 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()

Yes, get ahold of ApplicationContext and call .getBeanDefinitionNames()

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

You can get the context by:

  • 实现ApplicationContextAware
  • 使用@Inject/@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天全站免登陆