1515 */
1616package org .springframework .data .repository .aot .hint ;
1717
18+ import java .lang .annotation .Annotation ;
1819import java .util .Arrays ;
20+ import java .util .Collection ;
21+ import java .util .List ;
1922import java .util .Properties ;
2023
2124import org .jspecify .annotations .Nullable ;
2225
2326import org .springframework .aop .SpringProxy ;
2427import org .springframework .aop .framework .Advised ;
28+ import org .springframework .aot .hint .ExecutableMode ;
2529import org .springframework .aot .hint .MemberCategory ;
2630import org .springframework .aot .hint .RuntimeHints ;
2731import org .springframework .aot .hint .RuntimeHintsRegistrar ;
2832import org .springframework .aot .hint .TypeReference ;
2933import org .springframework .beans .factory .BeanFactory ;
3034import org .springframework .core .DecoratingProxy ;
35+ import org .springframework .core .annotation .AnnotatedElementUtils ;
3136import org .springframework .core .io .InputStreamSource ;
37+ import org .springframework .data .domain .AbstractAggregateRoot ;
38+ import org .springframework .data .domain .AfterDomainEventPublication ;
39+ import org .springframework .data .domain .DomainEvents ;
3240import org .springframework .data .domain .Example ;
3341import org .springframework .data .mapping .context .MappingContext ;
3442import org .springframework .data .repository .core .RepositoryMetadata ;
4250import org .springframework .data .repository .query .QueryByExampleExecutor ;
4351import org .springframework .data .repository .query .ReactiveQueryByExampleExecutor ;
4452import org .springframework .data .util .ReactiveWrappers ;
53+ import org .springframework .util .ReflectionUtils ;
4554
4655/**
4756 * {@link RuntimeHintsRegistrar} holding required hints to bootstrap data repositories. <br />
4857 * Already registered via {@literal aot.factories}.
4958 *
5059 * @author Christoph Strobl
5160 * @author Mark Paluch
61+ * @author Oliver Drotbohm
5262 * @since 3.0
5363 */
5464class RepositoryRuntimeHints implements RuntimeHintsRegistrar {
5565
66+ private static final Collection <Class <? extends Annotation >> DOMAIN_EVENT_ANNOTATIONS = List
67+ .of (AfterDomainEventPublication .class , DomainEvents .class );
68+
5669 @ Override
5770 public void registerHints (RuntimeHints hints , @ Nullable ClassLoader classLoader ) {
5871
@@ -72,6 +85,17 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
7285 builder .withMembers (MemberCategory .INVOKE_PUBLIC_METHODS );
7386 });
7487
88+ // Register event handling methods on AbstractAggregateRoot for reflection
89+ ReflectionUtils .doWithLocalMethods (AbstractAggregateRoot .class , method -> {
90+
91+ DOMAIN_EVENT_ANNOTATIONS .forEach (it -> {
92+
93+ if (AnnotatedElementUtils .isAnnotated (method , it )) {
94+ hints .reflection ().registerMethod (method , ExecutableMode .INVOKE );
95+ }
96+ });
97+ });
98+
7599 if (ReactiveWrappers .PROJECT_REACTOR_PRESENT ) {
76100
77101 // repository infrastructure
0 commit comments