title: Java MongoDB ClassNotFoundException: org.springframework.data.convert.CollectionFactory
body: <p>I'm trying to get all documents inside a collection and add them to a <code>List</code> as java objects, however when I run <code>findAll</code>, I get the following exception: </p>
  
  <pre><code>java.lang.ClassNotFoundException: org.springframework.data.convert.CollectionFactory
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_65]
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_65]
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_65]
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_65]
  ...
  </code></pre>
  
  <p>And this is the related error log:</p>
  
  <pre><code>2016-01-17 20:54:05.956 ERROR 87437 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/convert/CollectionFactory] with root cause
  </code></pre>
  
  <p>Here's the code that results in the exception: </p>
  
  <pre><code>public List&lt;TruckEntity&gt; findAll() {
  
      MongoClient mongoClient = new MongoClient("localhost", 27017);
      MongoOperations mongo = new MongoTemplate(mongoClient, "trucksDb");
  
      List&lt;TruckEntity&gt; trucks = mongo.findAll(TruckEntity.class);
  
      return trucks;
  }
  </code></pre>
  
  <p>the line <code>List&lt;TruckEntity&gt; trucks = mongo.findAll(TruckEntity.class);</code> is where the exception is thrown.</p>
  
  <p>When I use 
  <code>FindIterable&lt;Document&gt; iterable = db.getCollection("restaurants").find();
  </code> I can access the documents using the iterator, so the documents are there as <code>TruckEntity</code> class and there's no problem connecting to MongoDB. It's just the conversion is failing because of the missing class.</p>
  
  <p>I have <code>spring-data-mongodb</code> and <code>mongo-java-driver</code> included in my <code>pom.xml</code>. Is there anything I'm missing?</p>