我的端到端测试有问题:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestPropertySource(locations = {"classpath:test.properties"})
public class ConfigurationTest {
...
}
test.properties
:
server.port=56156
如果我在本地运行测试,一切都很好。但是如果我在 VM 上运行这个测试,每次我收到一个错误:
06:22:20 ***************************
06:22:20 APPLICATION FAILED TO START
06:22:20 ***************************
06:22:20
06:22:20 Description:
06:22:20
06:22:20 The Tomcat connector configured to listen on port 0 failed to start. The port may already be in use or the connector may be misconfigured.
在运行该测试之前,我确定该端口是空闲的,并且没有进程正在使用它。但是当我在本地运行这个测试时,我在日志中发现这两行,可能看起来很糟糕:
2019-01-31 13:34:18,746 | INFO | main | TomcatWebServer | Tomcat initialized with port(s): 0 (https)
...
2019-01-31 13:34:30,751 | INFO | main | TomcatWebServer | Tomcat started on port(s): 56156 (https) with context path ''
看起来tomcat启动了两次?这是可能的?