我们计划用spring 4.0.6版本创建一个新的应用程序.我们使用可以返回"XML"或"JSON"的控制器.在以前的项目,我们使用JAX-RS API成功实施新泽西州和Spring支持REST,但是从学长读了几篇文章和建议后,他们说,弹簧提供了相当不错的REST支持.
如果我在不使用JAX-RS和Jersey的情况下使用Spring REST支持,那些让我感到困惑的一些要点是:
如何在Spring MVC中完成编组和解组?
编组或解组是否需要使用jax-rs.
如果弹簧自动处理编组和解编,那么它如何知道xmlRootElements.
我仍然感到困惑,如果Spring证明了REST的非常好的支持那么为什么人们仍然会使用Jersey进行REST?真的想了解更多细节.
如果我说错了,请忽略它.对示例的解释非常有用.
提前致谢!!
当用户尝试将两个休息端点与 WebClient 一起使用时,我对获得正确的响应感到有点困惑。我想在代码中将其用作异步和非阻塞。
我正在从控制器返回通量。代码详情如下:
控制器类方法如下所示:
@RequestMapping(method = RequestMethod.GET, path = "/v1/repos/{userName}", produces = "application/json")
public ResponseEntity<Flux<GithubRepo>> getUserReposDetails(
@PathVariable(name="userName",required = true) String userName) throws Exception{
return new ResponseEntity<>(this.getGitRepos(userName), HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)
它正在调用getGitRepos方法。方法详情如下:
private Flux<GithubRepo> getGitRepos(String userName) {
return webClient.get().uri("/users/{userName}/repos",userName).
exchangeToFlux(clientResponse -> clientResponse.bodyToFlux(GithubRepo.class)).map(github->{
github.setBranch(webClient.get()
.uri("/repos/{userName}/{branchName}/branches",userName,github.getBranch())
.retrieve().bodyToFlux(Branch.class).collectList());
return github;
});
}
Run Code Online (Sandbox Code Playgroud)
WebClient 是:
WebClient webClient = WebClient.builder().baseUrl("https://api.github.com").
defaultHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.github.v3+json").build();
Run Code Online (Sandbox Code Playgroud)
GitHub 和 Branch 类如下:
@Data
public class GithubRepo {
private String name;
private String ownerLogin;
private Mono<List<Branch>> branch;
@JsonProperty("owner")
private void unpackNested(Map<String,String> …
Run Code Online (Sandbox Code Playgroud) java webclient reactive-programming spring-boot spring-webflux