Spring WebClient 放置映射:不支持内容类型 'application/json'

Spring WebClient put Mapping: Content type 'application/json' not supported

我正在尝试使用 WebClient 通过 REST 调用另一个服务,但我总是收到错误消息:

org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/json' not supported

所有分配都有相同版本的依赖项,通过 Postman 调用资源工作正常。问题是当第一个应用程序作为代理(客户端)尝试调用第二个应用程序(服务)

我的服务器资源:

@RequestMapping(value = "/properties")
@PutMapping(consumes = APPLICATION_JSON_UTF8_VALUE)
@ResponseStatus(CREATED)
public void saveProperty(@Valid @RequestBody PropertyForm form) {
    service.save(new PropertyImpl(form));
}

我的客户资源:

WebClient client = WebClient.create(serviceUrl);

Mono<Void> save(PropertyForm form) {
    return client.put()
            .uri("properties")
            .contentType(MediaType.APPLICATION_JSON_UTF8)
            .body(BodyInserters.fromObject(form))
            .retrieve()
            .bodyToMono(Void.class);
}

我的 build.gradle 文件:

dependencies {
    compile "org.springframework.boot:spring-boot-starter-reactor-netty:2.0.4.RELEASE"
    compile "org.springframework.boot:spring-boot-starter-web:2.0.4.RELEASE"
    compile "org.springframework:spring-webflux:5.0.4.RELEASE"

    compile "javax.xml.bind:jaxb-api:2.3.0"
}

我是否缺少一些依赖项来启用 JSON contentType?这个例子很简单,但对我来说也很有问题。

表单模型:

class PropertyForm {

    private String group;
    private String key;
    private String value;
    // getters & setters
}

来源:https://gitlab.com/Berilzar/Sandbox

我终于找到了答案。问题实际上出在发送表格中。表格的范围是包,与setters/getters相同。在我将 PropertyForm 提取到 API 模块并制作所有内容后 public,它表示可以工作。

所以解决方案是将表单替换为:

public class PropertyForm {

    private String group;
    private String key;
    private String value;
    // public getters & setters
}

感谢您的帮助和时间。