Fra*_*ard 5 spring spring-mvc rx-java spring-boot hystrix
我试图从 Spring RestController 返回一个 Observable,但没有成功。我的代码如下:
@RestController
public class HystrixCommentController {
@GetMapping(value = "/com1/{id}")
public Observable<Comment> getComment1(@PathVariable int id) {
return Observable.just(new Comment());
}
}
Run Code Online (Sandbox Code Playgroud)
在邮递员中运行请求时,我总是收到以下错误:
{
"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"
}
Run Code Online (Sandbox Code Playgroud)
SpringBoot 2 不也像 Mono/Flux 一样支持 RestController 中的 rx.Observable 吗?
我需要手动将 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());
}
}
Run Code Online (Sandbox Code Playgroud)
没有成功:
{
"timestamp": "2018-07-08T18:21:42.918+0000",
"status": 406,
"error": "Not Acceptable",
"message": "Could not find acceptable representation",
"path": "/com1/1"
}
Run Code Online (Sandbox Code Playgroud)
所以这里的问题是我的 pom.xml 中缺少依赖项:
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava-reactive-streams</artifactId>
<version>1.2.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
感谢@Dovmo 发现问题
| 归档时间: |
|
| 查看次数: |
2116 次 |
| 最近记录: |