title: Can't get ${server.port} from application.yml in @SpringApplicationConfiguration annotated test
body: <p>I get a <code>-1</code> value returned when trying to get the <code>server.port</code> property from <code>application.yml</code> in a test context.</p>
  
  <p>I do black box testing of a Spring-bot app.
  Here's a test case:
  </p>
  
  <pre class="lang-java prettyprint-override"><code>@SpringApplicationConfiguration(TestConfiguration.class)
  public class StartupTest extends AbstractTestNGSpringContextTests implements EnvironmentAware {
  
      private static Logger logger = LoggerFactory.getLogger(StartupTest.class);
  
      @Value("${server.port}")
      private String port;
  
      @Value("${project.name}")
      private String name;
  
      private RelaxedPropertyResolver propertyResolver;
  
      @Override
      public void setEnvironment(Environment environment) {
          this.propertyResolver = new RelaxedPropertyResolver(environment);
      }
  
      @Test
      public void isAppUpAndRunning() {
          logger.debug("port: " + port);
          logger.debug("name: " + name);
          logger.debug("value for project.name: " + propertyResolver.getProperty("project.name"));
          logger.debug("value for server.port: " + propertyResolver.getProperty("server.port"));
          logger.debug("value for server.servlet-path: " + propertyResolver.getProperty("server.servlet-path"));
      }
  }
  </code></pre>
  
  <p>NB: <code>TestConfiguration.class</code> contains nothing but <code>@Configuration</code></p>
  
  <p>Output:</p>
  
  <pre class="lang-java prettyprint-override"><code>[DEBUG] com.project.StartupTest - Running with Spring Boot v1.3.3.RELEASE, Spring v4.2.5.RELEASE
  [INFO] com.project.StartupTest - The following profiles are active: test
  [INFO] com.project.StartupTest - Started StartupTest in 4.698 seconds (JVM running for 7.761)
  [DEBUG] com.project.StartupTest - port: ${server.port}
  [DEBUG] com.project.StartupTest - name: ${project.name}
  [DEBUG] com.project.StartupTest - value for project.name: MyProject
  [DEBUG] com.project.StartupTest - value for server.port: -1
  [DEBUG] com.project.StartupTest - value for server.servlet-path: /
  </code></pre>
  
  <p>So there's actually 2 questions here: </p>
  
  <ul>
  <li>why can't I get the properties injected with the <code>@Value</code> annotation?</li>
  <li>why can I get all <code>application.yml</code> properties with a <code>PropertyResolver</code> but <code>server.port</code> ?</li>
  </ul>
  
  <p>What I need ultimately is a convenient way to access all the <code>application.yml</code> properties in a 'classic' test (i.e. not a Spring integration test as I want to test the application as it is at runtime). I've tried using </p>
  
  <pre class="lang-java prettyprint-override"><code>@ContextConfiguration(classes = TestConfiguration.class, initializers = ConfigFileApplicationContextInitializer.class)
  </code></pre>
  
  <p>as well, but the problem remains the same.</p>