How to find port of Spring Boot container when running a spock test using property server.port=0

后端 未结 3 1096
广开言路
广开言路 2020-12-29 14:28

Given this entry in application.properties:

server.port=0

which causes Spring Boot to chose a random available port, and testi

3条回答
  •  臣服心动
    2020-12-29 14:54

    You could do this too:

    @Autowired
    private org.springframework.core.env.Environment springEnv;
    ...
    springEnv.getProperty("server.port");
    

提交回复
热议问题