Mar*_*rcF 5 java spring spring-mvc spring-boot
我想要禁用除健康端点之外的所有执行器端点.所有文档都描述了如何在资源属性中实现此目的:
endpoints.enabled=false
endpoints.health.enabled=true
Run Code Online (Sandbox Code Playgroud)
但我总是喜欢使用内联java配置.有人可以解释我可以在应用程序中配置相同的位置吗?
查看org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration,当 bean 丢失时会提供端点。一种选择是在您自己的配置类中提供它们。所有端点都启用了该字段。您可以提供所有这些,除了您需要的之外,设置为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;
}
}
Run Code Online (Sandbox Code Playgroud)