Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 将弹簧启动执行器健康状态从向上/向下转换为真/假_Spring Boot_Spring Boot Actuator_Actuator - Fatal编程技术网

Spring boot 将弹簧启动执行器健康状态从向上/向下转换为真/假

Spring boot 将弹簧启动执行器健康状态从向上/向下转换为真/假,spring-boot,spring-boot-actuator,actuator,Spring Boot,Spring Boot Actuator,Actuator,有没有办法从向上/向下更改状态字段值 {"status":"UP"} 正确/错误,如下所示: {"status":true} 我想使用与弹簧致动器相同的检查逻辑,无需定制检查逻辑,只想更新状态值。假设您的公司建立了新的API标准,因为有许多不同的框架组成了应用程序的范围,而我们不是只讨论Spring Boot应用程序(否则会有点恼人): 只需在/exactor/customstatus下实现您自己的@Endpoint,并在其下聚合所有HealthIndicators status'。您可能希

有没有办法从向上/向下更改状态字段值

{"status":"UP"}
正确/错误,如下所示:

{"status":true}

我想使用与弹簧致动器相同的检查逻辑,无需定制检查逻辑,只想更新状态值。

假设您的公司建立了新的API标准,因为有许多不同的框架组成了应用程序的范围,而我们不是只讨论Spring Boot应用程序(否则会有点恼人):


只需在
/exactor/customstatus
下实现您自己的
@Endpoint
,并在其下聚合所有
HealthIndicator
s status'。您可能希望从Spring Boots的
HealthEndpoint
CompositeHealthIndicator
类中获得关于如何做到这一点的灵感。(主题
HealthAggregator

以下代码将注册一个新的执行器端点
/health
,该端点使用与默认
/health
端点相同的机制

package.com.example;
导入org.springframework.boot.actuate.endpoint.annotation.endpoint;
导入org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
导入org.springframework.boot.actuate.health.HealthEndpoint;
导入org.springframework.boot.actuate.health.Status;
导入org.springframework.stereotype.Component;
@组成部分
@Endpoint(id=“health”)//将其更改为以其他名称公开端点
公共类BooleanHealthEndpoint{
健康终点健康终点;
公共布尔HealthEndpoint(HealthEndpoint HealthEndpoint){
this.healthEndpoint=healthEndpoint;
}
@再手术
公共卫生{
布尔值health=healthEndpoint.health().getStatus().equals(Status.UP);
回归新健康(健康);
}
公共卫生{
私有布尔状态;
公共卫生(布尔状态){
这个状态=状态;
}
公共布尔getStatus(){
返回状态;
}
}
}
如果不想添加自定义的
/health
端点并继续使用默认的
/health
端点,可以在属性文件中添加以下设置,然后将其映射到默认设置:

management.endpoints.web.path-mapping.health=internal/health
management.endpoints.web.path-mapping.healthy=/health

这听起来并不自然:“你的身份是什么?真的”。。。。。很可能这是我公司的新API标准,他们希望看到的是真/假,而不是上/下。很高兴没有人必须遵循这个虚构的标准谢谢你的回答!!完全忘了这个问题。我能够使它与HealthAggregator一起工作,但现在由于这个类在较新的springboot版本中被弃用,我必须找到一种新的方法,您的解决方案绝对有效!!这只是对可能感兴趣的任何人的一个更新,如果您希望使用与默认端点相同的/health端点,我将使用属性映射更新答案