Punter Vicky Punter Vicky - 5 months ago 34x
Java Question

Print all the Spring beans that are loaded

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


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

You can get the context by:

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

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