Closed
Description
I have a DDD project where I expose a domain object which extends AbstractAggregateRoot:
public class Document extends AbstractAggregateRoot<Document> {
@Id
public String id;
public Document() {
this.registerEvent(new DocumentCreated(this));
}
public void readyToRun() {
this.registerEvent(new DocumentReadyToRun(this.id));
}
}
Additionally there is a domain event listener in the same domain:
@Component
public class DocumentEventListener {
@ApplicationModuleListener
public void handle(DocumentCreated event) {
event.document().readyToRun();
}
}
In the other domain there is an additional event listener:
@Component
public class OtherDomainEventListener {
@ApplicationModuleListener
public void handle(DocumentReadyToRun event) {
doWhatEverNeeded(event.documentId());
}
}
Generally it uses the spring mongo implementation as the storage layer. If the service is called the following exception is thrown:
java.util.ConcurrentModificationException: null
at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1095) ~[na:na]
at java.base/java.util.ArrayList$Itr.next(ArrayList.java:1049) ~[na:na]
at java.base/java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1078) ~[na:na]
at org.springframework.data.repository.core.support.EventPublishingRepositoryProxyPostProcessor$EventPublishingMethod.publishEventsFrom(EventPublishingRepositoryProxyPostProcessor.java:199) ~[spring-data-commons-3.3.1.jar:3.3.1]
at org.springframework.data.repository.core.support.EventPublishingRepositoryProxyPostProcessor$EventPublishingMethodInterceptor.invoke(EventPublishingRepositoryProxyPostProcessor.java:116) ~[spring-data-commons-3.3.1.jar:3.3.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.10.jar:6.1.10]
at org.springframework.data.mongodb.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:158) ~[spring-data-mongodb-4.3.1.jar:4.3.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.10.jar:6.1.10]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-6.1.10.jar:6.1.10]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.10.jar:6.1.10]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223) ~[spring-aop-6.1.10.jar:6.1.10]
at jdk.proxy3/jdk.proxy3.$Proxy120.save(Unknown Source) ~[na:na]
....