Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Mautsch committed Jul 6, 2024
1 parent b9548ba commit 6fa53e5
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;
import java.util.Arrays;
Expand Down Expand Up @@ -52,9 +53,7 @@ public void init() {
private void setupSubscription(Object bean, Method method, NatsListener natsListener) {
Arrays.stream(natsListener.subjects()).forEach(subject -> {
natsSubscription.create(natsListener.consumerName(), subject, (msg, eventData) -> {
try {
method.invoke(bean, msg.getSubject(), eventData);
} catch (Exception e) { throw new IllegalStateException(e); }
ReflectionUtils.invokeMethod(method, bean, msg.getSubject(), eventData);
});
});
}
Expand All @@ -64,20 +63,13 @@ static class ApplicationRuntimeHints implements RuntimeHintsRegistrar {
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints.reflection().registerType(NatsListenerAspect.class, MemberCategory.INVOKE_DECLARED_METHODS);

//hints.reflection().registerType(NatsLoggerConsumer.class, MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS);
//hints.reflection().registerType(NatsCalendarConsumer.class, MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS);

ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
//scanner.addIncludeFilter(new AssignableTypeFilter(Object.class));
var scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AnnotationTypeFilter(Component.class));

scanner.findCandidateComponents("org.goafabric").forEach(beanDefinition -> {
try {
Class<?> clazz = ClassUtils.forName(beanDefinition.getBeanClassName(), classLoader);
System.out.println(clazz.getName());
for (Method method : clazz.getDeclaredMethods()) {
if (method.isAnnotationPresent(NatsListener.class)) {
System.err.println("###" + method.isAnnotationPresent(NatsListener.class) + clazz.getName() + method.getName());
hints.reflection().registerMethod(method, ExecutableMode.INVOKE);
}
}
Expand Down

0 comments on commit 6fa53e5

Please sign in to comment.