diff --git a/src/main/java/codes/thischwa/dyndrest/config/PostProcessor.java b/src/main/java/codes/thischwa/dyndrest/config/PostProcessor.java index 8cae3f3..d33742b 100644 --- a/src/main/java/codes/thischwa/dyndrest/config/PostProcessor.java +++ b/src/main/java/codes/thischwa/dyndrest/config/PostProcessor.java @@ -51,25 +51,29 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) @Nullable @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - Collection> toBeRemoved = new HashSet<>(); - for (Class wantedBean : wanted) { - if (wantedBean.isInstance(bean) && !initialized.contains(bean)) { - initialized.add(bean); - toBeRemoved.add(wantedBean); - } - } - wanted.removeAll(toBeRemoved); + processBean(bean); if (!processed && wanted.isEmpty()) { - log.info("*** Relevant beans found!"); + log.info("*** Wanted beans found!"); try { process(initialized); } catch (Exception e) { throw new BeanInitializationException( - "Error while processing " + this.getClass().getName()); + "Error while processing " + this.getClass().getName(), e); } processed = true; } return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName); } + + private void processBean(Object bean) { + Collection> toBeRemoved = new HashSet<>(); + for (Class wantedBean : wanted) { + if (wantedBean.isInstance(bean) && !initialized.contains(bean)) { + initialized.add(bean); + toBeRemoved.add(wantedBean); + } + } + wanted.removeAll(toBeRemoved); + } }