Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
Last active May 8, 2023 07:17
Show Gist options
  • Save sandipchitale/ae4cf6c41833e67abbbcb1300b28f314 to your computer and use it in GitHub Desktop.
Save sandipchitale/ae4cf6c41833e67abbbcb1300b28f314 to your computer and use it in GitHub Desktop.
Dump bean names and class names #springframework
@Component
public static class CLR implements CommandLineRunner, ApplicationContextAware {
private ApplicationContext applicationContext;
@Override
public void run(String... args) throws Exception {
if (this.applicationContext != null) {
String[] beanDefinitionNames = this.applicationContext.getBeanDefinitionNames();
for (String beanDefinitionName : beanDefinitionNames) {
System.out.println("Bean: " + beanDefinitionName + " = "
+ this.applicationContext.getBean(beanDefinitionName).getClass().getName());
}
}
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment