You can use a BeanPostProcessor
for this. It will be notified of any bean before and after initialisation:
public class PrintingBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
System.out.println("Before init: " + beanName);
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
System.out.println("After init: " + beanName);
return bean;
}
}
To register it, in my configuration class I simply do:
@Bean
public BeanPostProcessor postProcessor() {
return new PrintingBeanPostProcessor();
}
This then prints on startup:
Before init: resourceHandlerMapping
After init: resourceHandlerMapping
Before init: defaultServletHandlerMapping
After init: defaultServletHandlerMapping
Before init: mvcUriComponentsContributor
After init: mvcUriComponentsContributor
Before init: httpRequestHandlerAdapter
After init: httpRequestHandlerAdapter
(this is obviously just a fraction of what it prints)
Hope that helps,
Artur