我正在使用 spring boot 1.3.x 并尝试使用@WebIntegrationTest(randomPort=true)
and设置一些集成测试TestRestTemplate
。
我最初遇到的几个问题 -
@Autowired TestRestTemplate testRestTemplate;
没用,只好一起去TestRestTemplate testRestTemplate = new TestRestTemplate();
然后,@Value("${local.server.port}")
也没有工作。它抛出了无法解决的异常。所以不得不这样做 -
@Autowired Environment environment;
并且在@Test
方法中试图从环境中获取端口,但我得到的只是null
。所以那也行不通。
然后将端口更改为8080
使用application.properties
和仅使用@WebIntegrationTest
并手动设置TestRestTemplate
.
完成所有这些之后,我现在收到 Connection Refused 错误。
请帮忙。spring 文档没有帮助。
谢谢