Here is an example implementation of BeanFactoryPostProcessor that can help you:
class CollaboratorsFinder implements BeanFactoryPostProcessor { private final Object bean; private final Set<String> collaborators = new HashSet<String>(); CollaboratorsFinder(Object bean) { if (bean == null) { throw new IllegalArgumentException("Must pass a non-null bean"); } this.bean = bean; } @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { for (String beanName : BeanFactoryUtils.beanNamesIncludingAncestors(beanFactory)) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); if (beanDefinition.isAbstract()) { continue;
Of course, there is much more (if you also want to catch the proxies of your original bean or something else). And of course, the above code has not been fully tested.
EDIT: To use this, you need to declare it as a bean in the context of your application. As you already noticed, this requires your bean (the one you want to control) (as the arg constructor).
As your question relates to "bean hiearchy", I edited to search for bean names throughout the hierarchy ...IncludingAncestors . In addition, I assumed that your bean is singleton and that it can be embedded in a postprocessor (although theoretically postProcessor should be initialized before the other beans should see if this really works).
source share