title: Spring Boot Test failing to autowire port with LocalServerPort annotation
body: <p>I am running Spring Boot 2.0.1 and Junit 5. I am trying to get port within an integration test . However the port value is always zero. I am not sure what could be causing it. I have tried changing web environment enum to random port but nothing seems to be working. </p>
  
  <pre><code>package com.example.demo;
  
  import org.junit.Test;
  import org.junit.jupiter.api.extension.ExtendWith;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.boot.web.server.LocalServerPort;
  import org.springframework.test.context.junit.jupiter.SpringExtension;
  import static org.junit.jupiter.api.Assertions.assertNotEquals;
  
  @ExtendWith(SpringExtension.class)
  @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
  public class DemoApplicationTests {
  
  @LocalServerPort
  private int port;
  @Test
  
  
  public void printPort() throws Exception {
       assertNotEquals(port, 0);
  }
  }
  </code></pre>
  
  <p>The following is the pom (NB. only shows the dependencies) </p>
  
  <pre><code>&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;junit-jupiter.version&gt;5.2.0&lt;/junit-jupiter.version&gt;
          &lt;junit-platform.version&gt;1.2.0&lt;/junit-platform.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
           &lt;dependency&gt;
                  &lt;groupId&gt;org.junit.platform&lt;/groupId&gt;
                  &lt;artifactId&gt;junit-platform-launcher&lt;/artifactId&gt;
                  &lt;scope&gt;test&lt;/scope&gt;
                  &lt;version&gt;${junit-platform.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.junit.platform&lt;/groupId&gt;
                  &lt;artifactId&gt;junit-platform-engine&lt;/artifactId&gt;
                  &lt;scope&gt;test&lt;/scope&gt;
                  &lt;version&gt;${junit-platform.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
                  &lt;artifactId&gt;junit-jupiter-api&lt;/artifactId&gt;
                  &lt;scope&gt;test&lt;/scope&gt;
                  &lt;version&gt;${junit-jupiter.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
                  &lt;artifactId&gt;junit-jupiter-engine&lt;/artifactId&gt;
                  &lt;scope&gt;test&lt;/scope&gt;
                  &lt;version&gt;${junit-jupiter.version}&lt;/version&gt;
              &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&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;/dependencies&gt;
  </code></pre>
  
  <p>application.properties</p>
  
  <pre><code>server.port=8080
  </code></pre>