Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何编写集成测试来使用spring boot测试zuul负载平衡_Java_Spring Boot_Spring Cloud Netflix - Fatal编程技术网

Java 如何编写集成测试来使用spring boot测试zuul负载平衡

Java 如何编写集成测试来使用spring boot测试zuul负载平衡,java,spring-boot,spring-cloud-netflix,Java,Spring Boot,Spring Cloud Netflix,我正在尝试使用TestRestTemplate使用相对url进行http调用: @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) public class MyApiLoadBalancerIntegrationTests { @Autowired private TestRestTemplate restTemplate; @Test

我正在尝试使用TestRestTemplate使用相对url进行http调用:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
public class MyApiLoadBalancerIntegrationTests {
    @Autowired
    private TestRestTemplate restTemplate;

    @Test
    public void whenSendRequestMyApiChoosingAnyServer() {
        ResponseEntity<String> responseEntity = restTemplate.getForEntity("/my-api/api-call", String.class);

        assertNotNull("Body was null", responseEntity.getBody());
        assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
    }

}
它不能正常工作,我无法直接调用服务器的api


有什么想法吗?

我已经成功了。你能将你的解决方案作为评论发布吗?遇到类似的问题。我不得不切换zuul ribbon http客户端库,因为默认的apache http库发送头来压缩内容,即使请求是一个没有正文的get。zuul.ribbon.okhttp.enabled=true加上此值,可在gradle编译组中引入依赖项:“com.squareup.okhttp3”,名称:“okhttp”,版本:“3.6.0”
zuul.routes.my-api.path= /my-api/**
zuul.routes.my-api.serviceId= my-api-servers

ribbon.eureka.enabled= false
my-api-servers.ribbon.listOfServers= ip1:8080, ip2:8080