diff --git a/pom.xml b/pom.xml
index 8bb4250..b76eb19 100644
--- a/pom.xml
+++ b/pom.xml
@@ -211,6 +211,7 @@
${maven.compiler.target}
+ UTF-8
diff --git a/src/main/java/org/axonframework/springboot/aot/MessageHandlerRuntimeHintsRegistrar.java b/src/main/java/org/axonframework/springboot/aot/MessageHandlerRuntimeHintsRegistrar.java
index 4dd257b..40fbf7a 100644
--- a/src/main/java/org/axonframework/springboot/aot/MessageHandlerRuntimeHintsRegistrar.java
+++ b/src/main/java/org/axonframework/springboot/aot/MessageHandlerRuntimeHintsRegistrar.java
@@ -16,9 +16,17 @@
package org.axonframework.springboot.aot;
+import org.axonframework.common.Priority;
+import org.axonframework.common.ReflectionUtils;
+import org.axonframework.common.annotation.AnnotationUtils;
import org.axonframework.messaging.Message;
import org.axonframework.messaging.annotation.AnnotatedHandlerInspector;
+import org.axonframework.messaging.annotation.ClasspathParameterResolverFactory;
import org.axonframework.messaging.annotation.MessageHandlingMember;
+import org.axonframework.messaging.annotation.MultiParameterResolverFactory;
+import org.axonframework.messaging.annotation.ParameterResolver;
+import org.axonframework.messaging.annotation.ParameterResolverFactory;
+import org.axonframework.modelling.command.AggregateMember;
import org.axonframework.queryhandling.annotation.QueryHandlingMember;
import org.axonframework.spring.config.MessageHandlerLookup;
import org.springframework.aot.generate.GenerationContext;
@@ -31,10 +39,17 @@
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import java.lang.reflect.Constructor;
+import java.lang.reflect.Executable;
import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* BeanFactoryInitializationAotProcessor that registers message handler methods declared on beans for reflection. This
@@ -50,19 +65,59 @@ public class MessageHandlerRuntimeHintsRegistrar implements BeanFactoryInitializ
@Override
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
- List> messageHandlingClasses =
+ Set> messageHandlingClasses =
MessageHandlerLookup.messageHandlerBeans(messageType(), beanFactory, true)
.stream()
.map(beanFactory::getType)
- .distinct()
- .collect(Collectors.toList());
- List> messageHandlingMembers = messageHandlingClasses
+ .collect(Collectors.toSet());
+
+ Set> detectedClasses = new HashSet<>();
+ messageHandlingClasses.forEach(c -> registerAggregateMembers(c, detectedClasses));
+
+ List> messageHandlingMembers = detectedClasses
.stream()
- .flatMap(beanType -> AnnotatedHandlerInspector.inspectType(beanType).getAllHandlers().values()
- .stream())
+ .flatMap(beanType ->
+ {
+ AnnotatedHandlerInspector> inspector = AnnotatedHandlerInspector.inspectType(
+ beanType,
+ MultiParameterResolverFactory.ordered(
+ ClasspathParameterResolverFactory.forClass(beanType),
+ new LenientParameterResolver()
+ ));
+ return Stream.concat(inspector.getAllHandlers().values().stream(),
+ inspector.getAllInterceptors().values().stream());
+ })
.flatMap(Collection::stream)
.collect(Collectors.toList());
- return new MessageHandlerContribution(messageHandlingClasses, messageHandlingMembers);
+ return new MessageHandlerContribution(detectedClasses, messageHandlingMembers);
+ }
+
+ private void registerAggregateMembers(Class> entityType, Set> reflectiveClasses) {
+ if (!reflectiveClasses.add(entityType)) {
+ return;
+ }
+
+ ReflectionUtils.fieldsOf(entityType).forEach(field -> {
+ Optional