我使用 Webflux 在 Spring Boot 2.1.8 应用程序上测试了 BlockHound,我在 bean 验证中遇到了阻塞调用。为了确保这不是由我们的逻辑引起的,我创建了一个带有一个端点的简单 Webflux 应用程序。
这是应用程序中的一个简单控制器:
@RestController
@RequestMapping("/v1/test")
@Validated
class TestController {
@PostMapping("/{type}", consumes = [MediaType.APPLICATION_JSON_VALUE])
fun testPost(@PathVariable type: String, @Valid @RequestBody entry: TestEntry): Mono<TestEntry> {
return Mono.just(TestEntry("${entry.data} - $type"))
}
}
@JsonInclude(JsonInclude.Include.NON_NULL)
data class TestEntry(
@field:NotNull val data: String?
)
Run Code Online (Sandbox Code Playgroud)
在主要方法中,我运行 Block Hound JVM 代理:
@SpringBootApplication
class DemoApplication
fun main(args: Array<String>) {
BlockHound.install()
runApplication<DemoApplication>(*args)
}
Run Code Online (Sandbox Code Playgroud)
向我的端点发送请求后,我收到此异常:
java.lang.Error: Blocking call! java.io.RandomAccessFile#readBytes
at reactor.blockhound.BlockHound$Builder.lambda$new$0(BlockHound.java:196) ~[blockhound-1.0.1.RELEASE.jar:na]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following …
Run Code Online (Sandbox Code Playgroud)