Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check which beans have loaded in spring context

I am having a series of odd errors in testing and deployment. They seem to indicate that some of my beans are not loading into the context, despite them being defined in applicationContext.xml.

Is there any way to check during testing which beans have actually been loaded? Or to find a complete list of beans loaded at run time?

Thanks, b

like image 894
Brian Dolan Avatar asked Mar 09 '13 04:03

Brian Dolan


People also ask

How do you check loaded beans in spring boot?

Spring Boot loads many beans into ApplicationContext on start up depends on the dependencies as per your pom. xml. You can call applicationContext. getBeanDefinitionNames() method to list all beans loaded into ApplicationContext.

How do you get loaded beans in the Spring?

In Spring Boot, you can use appContext. getBeanDefinitionNames() to get all the beans loaded by the Spring container.

How can we get list of all beans used in Spring application?

The ListableBeanFactory interface provides getBeanDefinitionNames() method which returns the names of all the beans defined in this factory. This interface is implemented by all the bean factories that pre-loads their bean definitions to enumerate all their bean instances.

Can you compare bean factory with application context?

The ApplicationContext comes with advanced features, including several that are geared towards enterprise applications, while the BeanFactory comes with only basic features. Therefore, it's generally recommended to use the ApplicationContext, and we should use BeanFactory only when memory consumption is critical.


1 Answers

At startup, Spring logs at info level the names of all the beans being loaded by a context. Or in code, you can use getBeanDefinitionNames() to get all the bean names.

like image 125
Ryan Stewart Avatar answered Oct 14 '22 07:10

Ryan Stewart