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.3vs.
org.mongodb mongo-java-driver 2.13.2 providedI 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.