title: Spring Boot with Embedded Mongo : Cannot assign requested address: JVM_Bind
body: <p>I am trying to setup a JUnit test for a Spring Boot with embedded Mongo &amp; Kafka :-</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
          classes = {AccountingApplication.class})
  @DataMongoTest
  public class BaseEmbeddedTest {
  
  
      @ClassRule
      public static KafkaEmbedded embeddedKafka = new KafkaEmbedded(1, true);
  
      @Autowired
      private MongoTemplate mongoTemplate;
  
  
      @Test
      public void emptyTest(){
  
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>src/test/resources/application.yml :-</p>
  </blockquote>
  
  <pre><code>spring:
    data:
      mongodb:
        port: 0
    kafka:
      bootstrap-servers: ${spring.embedded.kafka.brokers}
  </code></pre>
  
  <p><strong>PROBLEM</strong></p>
  
  <pre><code>Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.flapdoodle.embed.mongo.config.IMongodConfig]: Factory method 'embeddedMongoConfiguration' threw exception; nested exception is java.net.BindException: Cannot assign requested address: JVM_Bind
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
      ... 140 more
  Caused by: java.net.BindException: Cannot assign requested address: JVM_Bind
      at java.net.DualStackPlainSocketImpl.bind0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:106)
      at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
      at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:190)
      at java.net.ServerSocket.bind(ServerSocket.java:375)
      at java.net.ServerSocket.&lt;init&gt;(ServerSocket.java:237)
      at de.flapdoodle.embed.process.runtime.Network.getFreeServerPort(Network.java:80)
      at org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration.embeddedMongoConfiguration(EmbeddedMongoAutoConfiguration.java:147)
  </code></pre>
  
  <p>What am I doing wrong here ? </p>
  
  <p>Version:-</p>
  
  <pre><code>    dependencyManagementPluginVersion = '1.0.3.RELEASE'
      springBootVersion = '1.5.6.RELEASE'
      springCloudVersion = 'Dalston.SR2'
      projectVersion = '0.0.1-SNAPSHOT'
      javaVersion = 1.8
      kotlinVersion = '1.1.4'
  </code></pre>