[英]Disable spring boot actuator endpoints java config
I woud like to disable all actuator endpoints except for the health endpoint. 我想要禁用除健康端点之外的所有执行器端点。 All docs describe how to achieve this in the resource properties: 所有文档都描述了如何在资源属性中实现此目的:
endpoints.enabled=false
endpoints.health.enabled=true
but I have always preferred to use inline java configuration. 但我总是喜欢使用内联java配置。 Could someone please explain where in the application I can configure the same? 有人可以解释我可以在应用程序中配置相同的位置吗?
Looking at org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration , the endpoints are provided when the beans are missing. 查看org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration ,在缺少bean时提供端点。 One option would be to provide them in your own configuration class. 一种选择是在您自己的配置类中提供它们。 All endpoints have the field enabled . 所有端点都启用了该字段。 You could provide all of them, setting enabled on false , except for the one you need. 您可以提供所有这些设置,设置为false ,除了您需要的设置。
@Configuration
public class ActuatorConfiguration {
@Autowired(required = false)
private Collection<PublicMetrics> publicMetrics;
@Bean
public MetricsEndpoint metricsEndpoint() {
List<PublicMetrics> publicMetrics = new ArrayList<>();
if (this.publicMetrics != null) {
publicMetrics.addAll(this.publicMetrics);
}
Collections.sort(publicMetrics,AnnotationAwareOrderComparator.INSTANCE);
MetricsEndpoint metricsEndpoint = new MetricsEndpoint(publicMetrics);
metricsEndpoint.setEnabled(false);
return metricsEndpoint;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.