I would like to get the list of beans that are created in a Quarkus service. For that I have the below piece of code. Is this the correct way to get it?
@Inject
BeanManager beanManager;
void onStart(@Observes StartupEvent ev) {
final String SPACE = " ";
final AtomicInteger counter = new AtomicInteger();
final Set<Bean<?>> beans = beanManager.getBeans(Object.class, new AnnotationLiteral<Any>() {});
for (final Bean<?> bean : beans) {
LOGGER.info(counter.getAndIncrement() + SPACE + bean.getBeanClass().getName());
}
}
I have the same service in Spring Boot and I am trying to do exactly the same to know the list of beans that are created (the code is below).
public static void displayAllBeans() {
final String[] allBeanNames = applicationContext.getBeanDefinitionNames();
final AtomicInteger counter = new AtomicInteger();
final String SPACE = " ";
Arrays.stream(allBeanNames)
.map(beanName -> new StringBuilder()
.append(counter.getAndIncrement())
.append(SPACE)
.append(beanName)
.toString())
.forEach(System.out::println);
}
The result of the comparison is unbelievable. 18 beans are created in Quarkus vs 130 in Spring Boot. That is the reason I ask if I am getting the Quarkus beans in the correct way.
Thank you very much in advance.
Best regards.
question from:
https://stackoverflow.com/questions/65939754/how-to-get-all-the-created-beans-in-quarkus 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…