title: spring boot: ClassNotFoundException de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion
body: <p>I have an <a href="https://github.com/MaxHoefl/demo-mongodb" rel="nofollow noreferrer">example spring boot project</a> which uses mongo db for persisting objects. I would like to test it with an embedded mongo db but I get an error which is very similar to <a href="https://stackoverflow.com/questions/45956233/easiest-way-to-configure-embedded-mongodb">this question</a> (see comments of the accepted answer): For some reason <code>IFeatureAwareVersion</code> from <code>flapdoodle</code> cannot be found.</p>
  
  <pre><code>Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is java.lang.NoClassDefFoundError: de/flapdoodle/embed/mongo/distribution/IFeatureAwareVersion
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
      ... 65 common frames omitted
  Caused by: java.lang.NoClassDefFoundError: de/flapdoodle/embed/mongo/distribution/IFeatureAwareVersion
      at cz.jirutka.spring.embedmongo.EmbeddedMongoFactoryBean.&lt;init&gt;(EmbeddedMongoFactoryBean.java:47) ~[embedmongo-spring-1.3.1.jar:1.3.1]
      at com.example.MongoConfig.mongoTemplate(MongoConfig.java:37) ~[test-classes/:na]
      at com.example.MongoConfig$$EnhancerBySpringCGLIB$$108c2b8.CGLIB$mongoTemplate$0(&lt;generated&gt;) ~[test-classes/:na]
      at com.example.MongoConfig$$EnhancerBySpringCGLIB$$108c2b8$$FastClassBySpringCGLIB$$629c796a.invoke(&lt;generated&gt;) ~[test-classes/:na]
      at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.4.RELEASE.jar:5.0.4.RELEASE]
      at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
      at com.example.MongoConfig$$EnhancerBySpringCGLIB$$108c2b8.mongoTemplate(&lt;generated&gt;) ~[test-classes/:na]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_92]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_92]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_92]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_92]
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
      ... 66 common frames omitted
  Caused by: java.lang.ClassNotFoundException: de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_92]
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_92]
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_92]
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_92]
      ... 78 common frames omitted
  </code></pre>
  
  <p>Here is the pom </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;demo-mongodb&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;demo-mongodb&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.0.0.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;spring-cloud.version&gt;Finchley.M8&lt;/spring-cloud.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;de.flapdoodle.embed&lt;/groupId&gt;
              &lt;artifactId&gt;de.flapdoodle.embed.mongo&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;cz.jirutka.spring&lt;/groupId&gt;
              &lt;artifactId&gt;embedmongo-spring&lt;/artifactId&gt;
              &lt;version&gt;1.3.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
                  &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;spring-milestones&lt;/id&gt;
              &lt;name&gt;Spring Milestones&lt;/name&gt;
              &lt;url&gt;https://repo.spring.io/milestone&lt;/url&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;false&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>The Spring boot start parent <code>2.0.0.RELEASE</code> manages the version of <code>flapdoodle</code> which is <code>2.0.3</code> and I see the class <code>IFeatureAwareVersion</code> in the <code>de.flatpdoodle.embed.mongo-2.0.3.jar</code>.</p>
  
  <p>When I look at the dependancy hierarchy I see</p>
  
  <ul>
  <li><p><code>embedmongo-spring: 1.3.1 [test]</code></p>
  
  <ul>
  <li><code>de.flatpdoodle.embed.mongo: 2.0.3 (managed from 1.46.4) (ommitted for conflict with 2.0.3) [test]</code></li>
  <li><code>de.flatpdoodle.embed.process: 1.40.1 (ommitted for conflict with 2.0.2) [test]</code></li>
  </ul></li>
  </ul>
  
  <p>Here is the test</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(classes=MongoConfig.class)
  @TestPropertySource(locations = "classpath:application-test.properties")
  public class Test_TimezoneDao {
  
      private static final Logger LOG = LoggerFactory.getLogger(Test_TimezoneDao.class);
  
      //@Autowired private TimezoneDao dao;
      @Autowired private CounterService counterService;
  
      @Autowired
      private MongoTemplate mongoTemplate;
  
      @Test
      public void test() 
      {
          TimeZone tz = new TimeZone();
          tz.setId(counterService.getNextSequence());
          tz.setOffset(9);
          tz.setTz("Asia/Singapore");
  
          TimeZone tz2 = new TimeZone();
          tz2.setId(counterService.getNextSequence());
          tz2.setOffset(11);
          tz2.setTz("Australia/Sydney");
  
          mongoTemplate.save(tz);
  
          List&lt;TimeZone&gt; tzs = mongoTemplate.findAll(TimeZone.class, "timezones");
  
          for(TimeZone t : tzs)
          {
              LOG.info(t.toString());
          }
      }
  }
  </code></pre>
  
  <p>and here is the test config</p>
  
  <pre><code>@SpringBootConfiguration
  @Profile("test")
  @ComponentScan(basePackages= {"com.example.demomongodb"})
  @EnableJpaRepositories(basePackages= {"com.example.demomongodb"})
  @EnableMongoRepositories(basePackages= {"com.example.demomongodb"})
  @EntityScan(basePackages= {"com.example.demomongodb"})
  @EnableAutoConfiguration
  public class MongoConfig 
  {
      public MongoConfig()
      {
          System.out.println("============= LOADING MONGO CONFIG ===============");
      }
  
      @Bean
      public MongoTemplate mongoTemplate() throws IOException {
          EmbeddedMongoFactoryBean mongo = new EmbeddedMongoFactoryBean();
          mongo.setBindIp("localhost");
          MongoClient mongoClient = mongo.getObject();
          MongoTemplate mongoTemplate = new MongoTemplate(mongoClient, "test_or_whatever_you_want_to_call_this_db");
          return mongoTemplate;
      }
  }
  </code></pre>
  
  <p>Thanks for the help</p>