目前的里程碑(M4)的文件給出了一個示例如何使用WebClient
檢索Mono
:Spring 5 Web Reactive - 我們如何使用WebClient在Flux中檢索流數據?
WebClient webClient = WebClient.create(new ReactorClientHttpConnector());
ClientRequest<Void> request = ClientRequest.GET("http://example.com/accounts/{id}", 1L)
.accept(MediaType.APPLICATION_JSON).build();
Mono<Account> account = this.webClient
.exchange(request)
.then(response -> response.body(toMono(Account.class)));
我們怎樣才能獲得流傳輸數據(從返回text/event-stream
服務)爲流量使用Web客戶端?它支持自動傑克遜轉換嗎?
這是我在以前的里程碑做到了,但是API已經改變,無法找到如何做到這一點了:
final ClientRequest<Void> request = ClientRequest.GET(url)
.accept(MediaType.TEXT_EVENT_STREAM).build();
Flux<Alert> response = webClient.retrieveFlux(request, Alert.class)
目前的里程碑是M4 ...所以你可能要再次檢查文檔,M4版本中已完成很多工作來完成反應性功能。 –
我已經檢查過它,甚至目前的快照,但沒有關於這方面的細節。 – codependent
我查了Spring Framework 5 RC3,看來ClientRequest現在還沒有GET方法 – Sergey