问题描述
如何将 BlockHound 添加到 Spring Boot 应用程序以检测阻塞调用?
How to add BlockHound to spring boot app to detect blocking calls ?
我没有找到 Spring Boot 应用程序的任何示例:https://github.com/reactor/BlockHound/blob/master/文档/quick_start.md
I didn't find any examples for spring boot apps:https://github.com/reactor/BlockHound/blob/master/docs/quick_start.md
任何帮助将不胜感激.
推荐答案
恕我直言,最明智的选择是在 JUnit 测试执行代码时启用 BlockHound.
IMHO, the wisest choice would be to enable BlockHound while the code is being exercised by JUnit tests.
为此,您只需导入 https://mvnrepository.com/artifact/io.projectreactor.tools/blockhound-junit-platform 与测试范围的依赖关系,它会在您启动 JUnit 测试套件时自动初始化 BlockHound:
To do so you simply need to import the https://mvnrepository.com/artifact/io.projectreactor.tools/blockhound-junit-platform dependency with test scope, which automatically initializes BlockHound when you launch your JUnit tests suite:
<dependency>
<groupId>io.projectreactor.tools</groupId>
<artifactId>blockhound-junit-platform</artifactId>
<version>1.0.0.RC1</version>
<scope>test</scope>
</dependency>
或者,如果您打算一直使用 BlockHound - 而不仅仅是在测试期间 - 您应该导入以下依赖项:
Alternatively, if you intend to use BlockHound at all times - and not only during tests - you should instead import the following dependency:
<dependency>
<groupId>io.projectreactor.tools</groupId>
<artifactId>blockhound</artifactId>
<version>1.0.0.RC1</version>
</dependency>
并在您的主方法中调用 BlockHound.install()
,就在引导您的 Spring Boot 应用程序之前:
And call BlockHound.install()
in your main method, just before bootstrapping your Spring Boot application:
@SpringBootApplication
public class BlockhoundDemoApplication {
public static void main(String[] args) {
BlockHound.install();
SpringApplication.run(BlockhoundDemoApplication.class, args);
}
}
进一步参考可以参考:
- 我的文章@https://medium.com/@domenicosibilio/blockhound-detect-blocking-calls-in-reactive-code-before-its-too-late-6472f8ad50c1 在这里我解释了如何集成和定制 BlockHoundSpring Boot 2.2 应用程序中的 JUnit 测试;
- 我在 GitHub 上的演示项目,它为 JUnit 测试集成和定制了 BlockHound;
- BlockHound 文档(请参阅支持的测试框架em> 部分);
- BlockHound Gitter 频道,您可以在此询问有关 BlockHound 的问题.
- my article @ https://medium.com/@domenicosibilio/blockhound-detect-blocking-calls-in-reactive-code-before-its-too-late-6472f8ad50c1 where I explain how to integrate and customize BlockHound for JUnit testing in a Spring Boot 2.2 application;
- my demo project over at GitHub that integrates and customizes BlockHound for JUnit testing;
- the BlockHound docs (see the supported testing frameworks section);
- the BlockHound Gitter channel, where you can ask questions about BlockHound.
这篇关于如何将 BlockHound 添加到 Spring Boot 应用程序以检测阻塞调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!