From a42e656682722c8bdcd0be0b9f873e72ee19ffed Mon Sep 17 00:00:00 2001 From: Andreas Mautsch Date: Sat, 6 Jul 2024 12:47:39 +0200 Subject: [PATCH] changes --- .../consumer/nats/NatsListenerAspect.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/goafabric/eventdispatcher/consumer/nats/NatsListenerAspect.java b/src/main/java/org/goafabric/eventdispatcher/consumer/nats/NatsListenerAspect.java index 52256cf..36cdc90 100644 --- a/src/main/java/org/goafabric/eventdispatcher/consumer/nats/NatsListenerAspect.java +++ b/src/main/java/org/goafabric/eventdispatcher/consumer/nats/NatsListenerAspect.java @@ -36,18 +36,15 @@ public NatsListenerAspect(NatsSubscription natsSubscription, ApplicationContext @PostConstruct public void init() { - String[] beanNames = applicationContext.getBeanDefinitionNames(); - for (String beanName : beanNames) { - if (!beanName.equals("natsListenerAspect")) { - Object bean = applicationContext.getBean(beanName); - Arrays.stream(AopUtils.getTargetClass(bean).getDeclaredMethods()) - .filter(method -> method.isAnnotationPresent(NatsListener.class)) - .forEach(method -> { - NatsListener natsListener = method.getAnnotation(NatsListener.class); - setupSubscription(bean, method, natsListener); - }); - } - } + Arrays.stream(applicationContext.getBeanDefinitionNames()) + .filter(beanName -> !beanName.equals("natsListenerAspect")) + .forEach(beanName -> { + var bean = applicationContext.getBean(beanName); + Arrays.stream(AopUtils.getTargetClass(bean).getDeclaredMethods()) + .filter(method -> method.isAnnotationPresent(NatsListener.class)) + .forEach(method -> setupSubscription(bean, method, method.getAnnotation(NatsListener.class))); + }); + } private void setupSubscription(Object bean, Method method, NatsListener natsListener) {