我有一个在不同环境中运行的 Spring Boot 2.7 应用程序。根据环境的不同,会暴露不同的执行器端点(开发环境都暴露了)。
执行器基本路径更改为:
management.endpoints.web.base-path=/
因此,例如,健康路径是:
localhost:8080/health
我有一个
OncePerRequestFilter
,我需要不过滤执行器路径。
如果我使用
management.endpoints.web.exposure.include
,则我的开发环境的值为 *
。但我不能用它来进行 shouldNotFilter
检查。
我需要一个实际的列表,例如
[/info,/health,...]
。我什至不需要 /
,因为我可以将其添加到我的匹配器中,但如果它有它那就太好了。
是否有什么东西可以将公开的执行器端点拉入列表中,而无需我对列表进行硬编码?
谢谢。
您可以尝试这样的操作,这还列出了您添加到执行器的任何额外自定义端点:
import java.util.List;
import org.springframework.boot.actuate.endpoint.EndpointId;
import org.springframework.boot.actuate.endpoint.EndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint;
import org.springframework.stereotype.Component;
@Component
public class ActuatorEndpoints {
private final EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier;
public ActuatorEndpoints(final EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
this.endpointsSupplier = endpointsSupplier;
}
public List<String> list() {
return endpointsSupplier.getEndpoints().stream()
.map(ExposableWebEndpoint::getEndpointId)
.map(EndpointId::toString)
.toList();
}
}