我试图使用Web客户端通过REST另一个服务调用,但我总是得到错误:
org.springframework.web.reactive.function.UnsupportedMediaTypeException:内容类型“应用/ JSON的”不支持
所有分配有依赖的相同版本,调用资源,通过邮差工作正常。问题是,当第一应用程序,充当代理(客户端),试图调用一个第二(服务)
我的服务器资源:
@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
}
我终于找到了答案。问题是在发送形式实际上。形式的范围是包一样,同样设置器/吸气剂。我已提取的PropertyForm到API模块,并取得一切公开后,据称工作。
因此,解决办法是,以取代形式:
public class PropertyForm {
private String group;
private String key;
private String value;
// public getters & setters
}
感谢您的帮助和时间。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句