Skip to content

Commit fd58596

Browse files
committed
Conditionally create actuator task scheduler
Add @ConditionalOnBean(MeterRegistry.class) to the actuatorTaskScheduler bean so the scheduler is only created when a MeterRegistry is present. Also add imports for MeterRegistry and ConditionalOnBean. This avoids registering the monitored ThreadPoolTaskScheduler when Micrometer is not available.
1 parent 2e7b25b commit fd58596

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorAutoConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
*/
1717
package io.microsphere.spring.boot.actuate.autoconfigure;
1818

19+
import io.micrometer.core.instrument.MeterRegistry;
1920
import io.microsphere.annotation.ConfigurationProperty;
2021
import io.microsphere.spring.boot.actuate.MonitoredThreadPoolTaskScheduler;
2122
import org.springframework.beans.factory.annotation.Value;
2223
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
2324
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2426
import org.springframework.context.annotation.Bean;
2527
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
2628

@@ -101,6 +103,7 @@ public class ActuatorAutoConfiguration {
101103
* @param threadNamePrefix the prefix for thread names created by the scheduler
102104
* @return a configured {@link ThreadPoolTaskScheduler} instance
103105
*/
106+
@ConditionalOnBean(MeterRegistry.class)
104107
@Bean(name = ACTUATOR_TASK_SCHEDULER_SERVICE_BEAN_NAME, destroyMethod = "shutdown")
105108
public ThreadPoolTaskScheduler actuatorTaskScheduler(
106109
@Value(TASK_SCHEDULER_POOL_SIZE_VALUE_EXPRESSION) int poolSize,

0 commit comments

Comments
 (0)