我目前正在努力与Springs反应式WebClient调用Rest-Service。我从Springs UnsupportedOperationException获得了decodeToMono -function的Jaxb2XmlDecoder

public Mono<T> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
  throw new UnsupportedOperationException();
}

我的WebClient呼叫:
ResponseEntity<MyAsyncResponse> result = webClient.post()
        .contentType(MediaType.APPLICATION_XML)
        .syncBody(payload)
        .exchange()
        .flatMap(res -> res.toEntity(MyAsyncResponse.class))
        .block();

其余服务:
@RestController
public class MyAsyncController {

  @PostMapping(path = "foo")
  private CompletableFuture<MyAsyncResponse> getFoo() {
    return getMyAsyncResponse();
  }

  ...

我必须配置什么,才能使用合适的Decoder -implementation?这是一个普通的旧版Spring-MVC(v5.0.3)应用程序,而不是Spring-Boot

最佳答案

Jaxb2XmlDecoder没有实现decodeToMono,但现在已通过SPR-16759进行了修复。因此,仅升级到Spring Framework 5.0.6+ / Spring Boot 2.0.2+应该可以避免报告的异常。

09-25 22:22