0

What should be the place holder value to get running random port for programmatically configured http port in undertow?

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,properties = "server.http.port=0")
public class Test1 {

     @LocalServerPort
     private int port;

     @Value("${?}")
     private int httpPort;

    @Test
    public void test()
    {
        System.out.println(port+"  "+httpPort);
        assertNotNull(new Object());
    }
}
Ryuzaki L
  • 37,302
  • 12
  • 68
  • 98
  • Does this answer your question? [Spring Boot - How to get the running port](https://stackoverflow.com/questions/30312058/spring-boot-how-to-get-the-running-port) – Ryuzaki L Jan 23 '20 at 10:19
  • see this answer https://stackoverflow.com/a/31254766/9959152 – Ryuzaki L Jan 23 '20 at 10:19
  • my application is running on two http ports as i have added extra http listener to web server config. one random port i am able to get using @LocalServerPort annotation but I need second random port value. I have tried @Value("${local.server.http.port}") but did not worked out as getting Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'local.server.http.port' in value "${local.server.http.port}" – Devendra Singh Jan 23 '20 at 12:23
  • as i am explicitly making server.http.port=0 in @SpringBootTest properties to make second port random. but not able to get running random port value. so what should be the value to "?" in below annotation: @Value("${?}") private int httpPort; – Devendra Singh Jan 23 '20 at 12:27

0 Answers0