使用 Spring Boot health 执行器时
http://localhost:8080/health
{"status":"UP","diskSpace":{"status":"UP","total":122588196864,"free":59227926528,"threshold":10485760},"mongo":{"status":"UP","version":"3.2.6"}}
现在我想检查其他条件,以便检查状态关闭时是否触发相关操作。我想要类似的东西
{"status":"Down"}
最佳答案
您可以编写您的自定义'Health Indicator ' 这将覆盖默认的运行状况指示器并编写您的实现(例如始终将状态返回为 down
)。
现在,由于仅需要测试应用程序,因此我建议使用 @Profile
对其进行注释,以便仅在应用程序启动时才激活它,例如 test
配置文件,例如:
@Component
@Profile("test")
public class MyHealthIndicator implements HealthIndicator {
这样,如果您使用 test
之外的任何配置文件启动应用,将使用默认的 HealthIndicator
。
关于java - 如何更改 Spring Boot 健康执行器结果以进行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42852607/