我的春季application.yaml:
management:
...
endpoint:
health:
show-details: ALWAYS
info:
enabled: false
health:
diskspace:
path: "some-path"
threshold: 536870912我想扩展/包装org.springframework.boot.actuate.system.DiskSpaceHealthIndicator以添加一些特定于应用程序的行为。有没有办法将我的应用程序配置为使用我自己的自定义版本,例如com.acme.myapp.CustomDiskSpaceHealthIndicator而不是org.springframework.boot.actuate.system.DiskSpaceHealthIndicator
发布于 2020-08-11 02:48:10
可以,您只需提供一个名为diskSpaceHealthIndicator的自定义DiskSpaceHealthIndicator,它将替换缺省bean
@Configuration
public class DiskSpaceHealthIndicatorConfiguration {
@Bean
public DiskSpaceHealthIndicator diskSpaceHealthIndicator(DiskSpaceHealthIndicatorProperties properties) {
return new MyDiskSpaceHealthIndicator(properties.getPath(), properties.getThreshold());
}
private static class MyDiskSpaceHealthIndicator extends DiskSpaceHealthIndicator {
public MyDiskSpaceHealthIndicator(File path, DataSize threshold) {
super(path, threshold);
}
@Override
protected void doHealthCheck(Builder builder) throws Exception {
// Do whatever you need here
super.doHealthCheck(builder);
builder.withDetail("custom details", "whatever");
}
}
}https://stackoverflow.com/questions/63344032
复制相似问题