title: Spring Boot - How to get the running port
body: <p>I have a spring boot application (using embedded tomcat 7), and I've set <code>server.port = 0</code> in my <code>application.properties</code> so I can have a random port.  After the server is booted up and running on a port, I need to be able to get the port that that was chosen.</p>
  
  <p>I cannot use <code>@Value("$server.port")</code> because it's zero.  This is a seemingly simple piece of information, so why can't I access it from my java code?  How can I access it?  </p>