title: Testing to see if port is in use before initializing bean
body: <p>I am using Spring Boot and have a bean that initializes an <code>EmbeddedServletContainerCustomizer</code>. I have a property file in which a user supplies a port and ip address to bind to (thus the need for an <code>EmbeddedServletContainerCustomizer</code> because the port is not the default that Spring boot uses). How can I test to see if the address and port combination is already in use prior to initializing this bean? I am not able to create a <code>ServerSocket</code> inside of this bean. I wish to have a graceful way of catching this exception and logging it. In the case that the port/ip combination is in use, Spring will shutdown with a stacktrace.</p>
  
  <pre><code>    @Bean
  public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer() throws UnknownHostException {
      EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer = null;
  
      embeddedServletContainerCustomizer = new EmbeddedServletContainerCustomizer() {
          @Override
          public void customize(ConfigurableEmbeddedServletContainer container) {
              container.setPort(port);
              container.setAddress(inetAddress);
          }
      };
  
      return embeddedServletContainerCustomizer;
  }
  </code></pre>