Hay*_*ych 5 swagger spring-boot spring-boot-actuator
我正在使用 Spring Actuator(版本 2.2.4.RELEASE)来生成可以正常工作的运行状况检查端点/localhost:8080/my-app/actuator/health。
这会生成访问时显示的 3 个端点,/actuator并显示在 Swagger(版本 2)中:
/actuator/health/actuator/health/{*path}(在我的招摇页面中,这显示为/actuator/health/**)/actuator/info由于 AWS 的原因,我遇到了问题,health/**想将其删除(我/info也想删除,因为我不需要它)。
我尝试将以下内容添加到我的application.properties文件中:
management.endpoints.web.exposure.exclude=health,info
Run Code Online (Sandbox Code Playgroud)
和
management.endpoints.jmx.exposure.exclude=health,info
Run Code Online (Sandbox Code Playgroud)
但这没有任何区别(它们仍然会生成)。我曾尝试使用它*来查看是否会强制所有端点消失,但它也不会改变任何内容。
知道如何解决这个问题吗?
我发现一个属性文件被另一个文件覆盖。因此,使用以下命令:
management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true
Run Code Online (Sandbox Code Playgroud)
摆脱/actuator/info端点。但是,我仍然需要摆脱 the/actuator/health/{*path}并保留/actuator/health端点。
正如执行器手册的“暴露端点”部分中所指定的,Web 默认情况下公开两个端点:health和info。
正如您正确注意到的那样,可以使用以下方法进行修改:
management.endpoints.web.exposure.excludemanagement.endpoints.web.exposure.include属性(不包括具有更高优先级的属性)。
因此,您可以轻松摆脱info端点。
现在,健康端点提供了 2 个 URL:
/actuator/health/actuator/health/{*path}我不清楚你离开前者并禁用后者的动机是什么,但我检查过你至少有两个选择:
选项 1 - 替换health为您自己的实现
您只需要:
HealthEndpointAutoConfiguration以删除默认运行状况端点health选项 2:离开/actuator/health但移除/actuator/health/{*path}
两个操作都定义在org.springframework.boot.actuate.health.HealthEndpoint
@Endpoint(id = "health")
public class HealthEndpoint extends HealthEndpointSupport<HealthContributor, HealthComponent> {
// ...
@ReadOperation
public HealthComponent health() {
HealthComponent health = health(ApiVersion.V3, EMPTY_PATH);
return (health != null) ? health : DEFAULT_HEALTH;
}
@ReadOperation
public HealthComponent healthForPath(@Selector(match = Match.ALL_REMAINING) String... path) {
return health(ApiVersion.V3, path);
}
}
Run Code Online (Sandbox Code Playgroud)
摆脱@ReadOperation第二种方法的最简单方法是:
HealthEndpoint到您的项目(注意:包必须匹配)@ReadOperation注释healthForPath HealthEndpointSupport防止IllegalAccessError类加载器不同造成的复制。| 归档时间: |
|
| 查看次数: |
6110 次 |
| 最近记录: |