Spring 启动 2 - 从 RestController 返回 rx.Observable
Spring Boot 2 - Returning rx.Observable from RestControler
我正在尝试从 Spring RestController return 一个 Observable,但没有成功。我的代码如下:
@RestController
public class HystrixCommentController {
@GetMapping(value = "/com1/{id}")
public Observable<Comment> getComment1(@PathVariable int id) {
return Observable.just(new Comment());
}
}
当运行邮递员的请求时,我总是得到以下错误:
{
"timestamp": "2018-07-08T16:07:36.809+0000",
"status": 500,
"error": "Internal Server Error",
"message": "No converter found for return value of type: class rx.internal.util.ScalarSynchronousObservable",
"path": "/com1/1"
}
SpringBoot 2 不也支持 rx.Observable 中的 RestController
就像他们对 Mono/Flux ?
所做的那样
我需要手动将 Observable 转换为 Mono/Flux 吗?
此致
注意:spring-boot-starter-webflux 包含在 pom
我试过这个:
@RestController
public class HystrixCommentController {
@GetMapping(value = "/com1/{id}", produces = "application/json")
public Observable<Comment> getComment1(@PathVariable int id) {
return Observable.just(new Comment());
}
}
没有成功:
{
"timestamp": "2018-07-08T18:21:42.918+0000",
"status": 406,
"error": "Not Acceptable",
"message": "Could not find acceptable representation",
"path": "/com1/1"
}
所以这里的问题是我的 pom.xml 中缺少依赖项:
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava-reactive-streams</artifactId>
<version>1.2.1</version>
</dependency>
感谢@Dovmo 发现问题
我正在尝试从 Spring RestController return 一个 Observable,但没有成功。我的代码如下:
@RestController
public class HystrixCommentController {
@GetMapping(value = "/com1/{id}")
public Observable<Comment> getComment1(@PathVariable int id) {
return Observable.just(new Comment());
}
}
当运行邮递员的请求时,我总是得到以下错误:
{
"timestamp": "2018-07-08T16:07:36.809+0000",
"status": 500,
"error": "Internal Server Error",
"message": "No converter found for return value of type: class rx.internal.util.ScalarSynchronousObservable",
"path": "/com1/1"
}
SpringBoot 2 不也支持 rx.Observable 中的 RestController 就像他们对 Mono/Flux ?
所做的那样
我需要手动将 Observable 转换为 Mono/Flux 吗?
此致
注意:spring-boot-starter-webflux 包含在 pom
我试过这个:
@RestController
public class HystrixCommentController {
@GetMapping(value = "/com1/{id}", produces = "application/json")
public Observable<Comment> getComment1(@PathVariable int id) {
return Observable.just(new Comment());
}
}
没有成功:
{
"timestamp": "2018-07-08T18:21:42.918+0000",
"status": 406,
"error": "Not Acceptable",
"message": "Could not find acceptable representation",
"path": "/com1/1"
}
所以这里的问题是我的 pom.xml 中缺少依赖项:
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava-reactive-streams</artifactId>
<version>1.2.1</version>
</dependency>
感谢@Dovmo 发现问题