I am using the below to display all spring beans in the context. How can I remove beans from the context?
ConfigurableApplicationContext ctx = SpringApplication.run(ProxyApplication.class, args);
for(String beanName:ctx.getBeanDefinitionNames()){
System.out.println(beanName);
}
You can do it this way:
ConfigurableApplicationContext ctx = SpringApplication.run(ProxyApplication.class, args);
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ctx.getAutowireCapableBeanFactory();
for(String beanName : ctx.getBeanDefinitionNames()){
System.out.println(beanName);
registry.removeBeanDefinition(beanName);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With