1 回答

TA贡献1859条经验 获得超6个赞
我认为您遇到的问题是由于SomeUtil.user()未发出值而引起的。
为什么我认为是这样的:我尝试了一个简单的例子来重现您的问题:
@Test
void test() {
Mono<String> monoWithContent =
Mono.just("Content")
.map(element -> exceptionThrower());
// TEST 1
StepVerifier.create(monoWithContent)
.expectError()
.verify();
Mono<String> monoWithoutContent =
Mono.empty()
.map(element -> exceptionThrower());
// TEST 2
StepVerifier.create(monoWithoutContent)
.expectError()
.verify();
}
String exceptionThrower() {
throw new RuntimeException();
}
结果是:
TEST 1 - 成功通过,因为该值是从发出的,Mono并且它被映射到一个异常(RuntimeException由exceptionThrower().
TEST 2 - 失败,因为没有要从中发出的值Mono,因此map不会调用该方法,并且整个执行完成且没有错误。
总而言之,如果 没有发出任何内容Publisher,则不会调用转换操作。
添加回答
举报