You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用Spring Boot应用中的默认Quartz Scheduler?

禁用Spring Boot默认的Quartz调度器

核心解决方案:排除Quartz自动配置

Spring Boot的自动配置机制会在检测到Quartz依赖时,默认创建一个名为quartzScheduler的调度器实例。要禁用这个默认实例,只需在Spring Boot启动类上排除对应的自动配置类:

@SpringBootApplication(exclude = QuartzAutoConfiguration.class)
public class YourSpringBootApplication {
    public static void main(String[] args) {
        SpringApplication.run(YourSpringBootApplication.class, args);
    }
}

额外修正:调整SchedulerFactoryBean初始化顺序

你当前的SchedulerManager中,schedulerFactory.afterPropertiesSet()的调用顺序有误——应先设置自定义JobFactory,再执行初始化操作,否则你的MyQuartzJobFactory不会生效。修正后的代码如下:

public void initScheduler() {
    try (InputStream propsInputStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("my-quartz.properties")) {
        log.info("Creating Quartz scheduler...");
        Properties myQuartzProperties = new Properties();
        myQuartzProperties.load(propsInputStream);

        SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
        schedulerFactory.setQuartzProperties(myQuartzProperties);
        // 先设置自定义JobFactory,再执行初始化
        schedulerFactory.setJobFactory(quartzJobFactory);
        schedulerFactory.afterPropertiesSet();

        this.scheduler = schedulerFactory.getScheduler();
        this.schedulingConfigMap = new HashMap<>();

        log.info("Quartz scheduler created.");
    } catch (Exception e) {
        log.error("Unable to create Quartz scheduler", e);
        throw new RuntimeException("Scheduler extension initialization error", e);
    }
}

内容的提问来源于stack exchange,提问作者Daniel Rodríguez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 15:45:57