Mongo-driver dependency issue

I’m integrating axon into an existing codebase (already using Spring & Mongo). When creating the EventStore, I was getting

nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘eventSourcingRepository’ defined in class path resource [com/ascentis/benefits/config/MongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.axonframework.eventsourcing.EventSourcingRepository]: Factory method ‘eventSourcingRepository’ threw exception; nested exception is java.lang.NoClassDefFoundError: com/mongodb/MongoException$DuplicateKey

note the last bit – “nested exception is java.lang.NoClassDefFoundError: com/mongodb/MongoException$DuplicateKey”

It was failing on

EventStore eventStore = new MongoEventStore(template);

but it was failing before the constructor (in the class loader)

Noticing that we’re using a later version of mongo-driver:

org.mongodb mongo-java-driver 2.9.3

vs.

org.mongodb mongo-java-driver 2.13.2 provided

I grabbed a copy of the code and updated the Axon-mongo pom.xml to use 2.13.2 and changed EventStore to use “com.mongodb.DuplicateKeyException” instead of the (deprecated / missing?) MongoException.DuplicateKey.

Hi Tim,

Axon was built against Mongo 2. In Mongo 3, they have changed the exceptions that you get, causing this ClassNotFoundError.
Focus right now is very much on Axon 3, which will definitely support the Mongo 3 API.
If time permits, we will include a new module for Mongo 3 in Axon 2.4.x, to remain backward compatible with Mongo 2.

Hope this helps.
Cheers,

Allard