diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/HikariDataSourceMetricsPostProcessor.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/HikariDataSourceMetricsPostProcessor.java index d50d221af2..d3898b3d0d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/HikariDataSourceMetricsPostProcessor.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/HikariDataSourceMetricsPostProcessor.java @@ -51,8 +51,11 @@ class HikariDataSourceMetricsPostProcessor implements BeanPostProcessor { private void bindMetricsRegistryToHikariDataSource(MeterRegistry registry, HikariDataSource dataSource) { - dataSource.setMetricsTrackerFactory( - new MicrometerMetricsTrackerFactory(registry)); + if (dataSource.getMetricRegistry() == null + && dataSource.getMetricsTrackerFactory() == null) { + dataSource.setMetricsTrackerFactory( + new MicrometerMetricsTrackerFactory(registry)); + } } private MeterRegistry getMeterRegistry() {