Spring boot 使用弹簧执行器时无法排除/info和/health/{*path}
我正在使用Spring Actuator(版本2.2.4.RELEASE)在Spring boot 使用弹簧执行器时无法排除/info和/health/{*path},spring-boot,swagger,spring-boot-actuator,Spring Boot,Swagger,Spring Boot Actuator,我正在使用Spring Actuator(版本2.2.4.RELEASE)在/localhost:8080/my app/Actuator/health生成运行状况检查端点,该端点工作正常 这将生成3个端点,在访问执行器时显示,并在Swagger(版本2)中显示: /exactor/health /exactor/health/{*path}(在我的招摇过市页面中,显示为/exactor/health/**) /exactor/info 由于AWS的原因,我的运行状况有问题/**,我想删除它(我
/localhost:8080/my app/Actuator/health
生成运行状况检查端点,该端点工作正常
这将生成3个端点,在访问执行器时显示,并在Swagger(版本2)中显示:
/exactor/health
/exactor/health/{*path}
(在我的招摇过市页面中,显示为/exactor/health/**
)/exactor/info
运行状况有问题/**
,我想删除它(我也想删除/info
,因为我不需要它)
我已尝试将以下内容添加到我的应用程序.properties
文件中:
management.endpoints.web.exposure.exclude=health,info
及
但这没有任何区别(它们仍然是生成的)。我尝试使用*
来查看这是否会迫使所有端点消失,但也不会改变任何东西
你知道我如何解决这个问题吗
编辑1
我发现一个属性文件被另一个文件覆盖。因此,请使用以下命令:
management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true
除去
/exactor/info
端点。然而,我仍然需要去掉/exactor/health/{*path}
,保留/exactor/health
端点。推荐的暴露招摇过市UI的方法是只启用特定路径。下面是一个示例,您可以使用它仅公开/rest/*
端点。你可以用你需要的任何图案来代替它
private-apinfo-apinfo(){
返回新的ApiInfoBuilder()
.标题(“给出一个有意义的标题”)
.description(“描述您的API”)
.termsOfServiceUrl(“放入您的T&C URL”)
.联系方式(“联系方式”)
.许可证(“许可证说明”)
.licenseUrl(“许可证端点”)
.版本(“API版本”)
.build();
}
私有谓词路径(){
返回或(regex(“/rest/*”);
}
@豆子
公共摘要新闻API(){
返回新摘要(DocumentationType.SWAGGER_2)
.groupName(“rest”)
.apinfo(apinfo())
.选择()
.path(路径())
.build();
}
这是一个仅允许您要公开的端点的示例
参见示例实现
查看端点的演示:使用登录
用户名堆栈
密码溢出
如执行机构手册章节所述,要查看摇摇摆摆。默认情况下,web会显示两个端点:运行状况
和信息
正如您正确注意到的,可以使用以下方法修改:
management.endpoints.web.exposure.exclude
management.endpoints.web.exposure.include
info
端点
现在,运行状况端点提供了2个URL:
/exactor/health
/exactor/health/{*path}
运行状况
你只需要:
- 排除
以删除默认的运行状况端点HealthEndpointAutoConfiguration
- 提供您自己的映射到<代码>健康
/exactor/health
但移除/exactor/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);
}
}
@Endpoint(id=“health”)
公共类HealthEndpoint扩展了HealthEndpointSupport{
// ...
@再手术
公共卫生部分(卫生){
HealthComponent health=health(ApiVersion.V3,空路径);
返回(健康!=null)?健康:默认健康;
}
@再手术
public HealthComponent healthForPath(@Selector(match=match.ALL_剩余)字符串…路径){
返回运行状况(ApiVersion.V3,路径);
}
}
对于第二种方法,消除@ReadOperation
的最简单方法是:
- 将
复制到项目中(注意:包必须匹配)HealthEndpoint
- 删除
healthForPath
- 复制
以防止不同类装入器导致的HealthEndpointSupport
IllegalAccessError
management.endpoints.web.exposure.exclude=health,info
同时禁用web端点和招摇输入。您是否已验证没有具有更高优先级的外部配置,从而覆盖了您的应用程序.properties
?对于所有属性源,检查@Lesiak,我已经解决了一个属性覆盖问题。然而,仍然存在一个问题。我已经用细节编辑了我的答案。
@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);
}
}