title: How to get local server host and port in Spring Boot?
body: <p>I'm starting up a Spring Boot application with <code>mvn spring-boot:run</code>.</p>
  
  <p>One of my <code>@Controller</code>s needs information about the host and port the application is listening on, i.e. <code>localhost:8080</code> (or <code>127.x.y.z:8080</code>). Following the <a href="http://docs.spring.io/spring-boot/docs/1.2.3.RELEASE/reference/html/common-application-properties.html">Spring Boot documentation</a>, I use the <code>server.address</code> and <code>server.port</code> properties:</p>
  
  <pre><code>@Controller
  public class MyController {
  
      @Value("${server.address}")
      private String serverAddress;
  
      @Value("${server.port}")
      private String serverPort;
  
      //...
  
  }
  </code></pre>
  
  <p>When starting up the application with <code>mvn spring-boot:run</code>, I get the following exception:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myController': Injection of autowired dependencies failed; nested exception is 
  org.springframework.beans.factory.BeanCreationException: Could not autowire field: ... String ... serverAddress; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'server.address' in string value "${server.address}"
  </code></pre>
  
  <p>Both <code>server.address</code> and <code>server.port</code> cannot be autowired.</p>
  
  <p>How can I find out the (local) host/address/NIC and port that a Spring Boot application is binding on?</p>