May 2015
Intermediate to advanced
234 pages
4h 18m
English
It can be useful, especially for debugging purposes, to list all the beans at a given moment.
We will use the code from the Defining a bean implicitly with @Component recipe, where we defined a UserService bean.
Here are the steps to retrieve the names of the beans currently in Spring's ApplicationContext object:
ApplicationContext field annotated with @Autowired:@Autowired private ApplicationContext applicationContext;
ApplicationContext and its getBeanDefinitionNames()method to get the list of bean names:String[] beans = applicationContext.getBeanDefinitionNames();
for (String bean : beans) {
System.out.println(bean);
} When the controller ...
Read now
Unlock full access