MongoSocketException when testing a new Saga


I have been building some software with Axon for a couple of months now, but I have got stuck on a particular issue.

My project is in Maven, with a Core module holding commands, events,etc… The query layer comes next in a separate module, with Spring Data injecting into a postgreSQL database. The domain layer is the third Maven module, holding the aggregates, and sagas, which are stored in Mongo. The fourth module holds some services, and the fifth module holds Web stuff.

I currently have one saga, which manages several subtasks for a parent task, and it works fine. I am trying to add a second saga which handles a different set of subtasks for the same parent. However, I am getting some very strange behaviour, and I cannot track down the root cause.

Specifically, I am seeing the following stack trace:

java.lang.NoClassDefFoundError: com/mongodb/MongoSocketException






at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(


at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(

at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(

at com.sun.proxy.$Proxy54.findByParentItemUuidAndNoteTypeAndActive(Unknown Source)

at TRUNCATED.end2end.NotesEndToEndIT.endToEndTest(

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(

at sun.reflect.DelegatingMethodAccessorImpl.invoke(

at java.lang.reflect.Method.invoke(

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(


at org.junit.runners.model.FrameworkMethod.invokeExplosively(

at org.junit.internal.runners.statements.InvokeMethod.evaluate(

at org.junit.internal.runners.statements.RunBefores.evaluate(

at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(

at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(

at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(

at org.junit.runners.ParentRunner$

at org.junit.runners.ParentRunner$1.schedule(

at org.junit.runners.ParentRunner.runChildren(

at org.junit.runners.ParentRunner.access$000(

at org.junit.runners.ParentRunner$2.evaluate(

at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(

at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(





at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(


at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

Caused by: java.lang.ClassNotFoundException: com.mongodb.MongoSocketException



at Method)


at java.lang.ClassLoader.loadClass(

at sun.misc.Launcher$AppClassLoader.loadClass(

at java.lang.ClassLoader.loadClass(

… 42 more

The specific line TRUNCATED.end2end.NotesEndToEndIT.endToEndTest ( reads as follows:

Set notesFound = noteRecordRepository.findByParentItemUuidAndNoteTypeAndActive(userUuid, NoteType.USER_NOTE, ACTIVE);

This command will retrieve notes from the JPA Repository in the Query layer.

During the @Before step of this test, I am setting up one of the Parent items, which triggers my new Saga. The new Saga will trigger another Command which is placed on the CommandGateway. If I disable the additional command, then my test works fine.

My initial Saga also submits additional commands to the CommandGateway, and does not suffer from this problem, so I confident that my approach should be sound, but I cannot understand why I am getting a MongoSocketException when trying to access a JPA Repository.

Any help is appreciated !


Mark Allen

Hi Mark,

sorry for the late reply. It has been busy around here the last couple of days.

This error is very likely a classpath issue, not so much a programming one. Do you have multiple versions of Spring Data and/or Mongo on the classpath? Are the versions of Spring Core, Spring Data and the Mongo client compatible?



Hi Allard,

Thank you very much for getting back to me. I have been looking into the versioning as suggested, but I cannot see a problem.

I am using Maven to manage the dependencies, which has not identified an issue. I have compared the output from “mvn dependency:tree” between my project, and the Axon-trader project, and I have ensured that the dependencies are matched.

Specifically, I am using:
spring-core 4.0.6.RELEASE
spring-data-mongodb 1.5.2.RELEASE
spring-data-jpa 1.6.2.RELEASE
spring-data-commons 1.8.2.RELEASE
mongo-java-driver 2.11.3

These versions are the same as used with Axon-trader. (Although the axon-trader uses axon 2.3 and I am using axon 2.3.2, I have tried moving the axon version back to 2.3, but the behaviour is still the same.)

What is most peculiar is that if I have a single Saga based on a PARENT object, it all works fine. When I add a second saga on the PARENT item, I start getting the MongoSocketException whist accessing a JPA repository.
Actually, scratch that, I just tried only wiring in the second saga, and I still have the same issue.

Very odd !


Hi Allard,
I think I may have made progress…

I have overridden the mongo version brought in by Axon from 2.11.x to 2.12.x, and my error message has become much more meaningful, and I can see a problem in my code.

You are right, that somehow the MongoSocketException from version 2.12.x is being thrown, and cannot be caught using mongo 2.11.x

There is clearly an issue with my dependencies as you correctly guessed first time.

Many Thanks for your help !