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

Spring与Quartz集成报错:Scheduler无getListenerManager()方法求解

解决java.lang.NoSuchMethodError: org.quartz.Scheduler.getListenerManager()问题

Ah, I’ve dealt with this exact Quartz version mismatch headache before—let’s get this sorted out step by step.

问题根源

The getListenerManager() method was introduced in Quartz 2.0, and your project is using quartz-all-1.6.1.jar, which is a very old 1.x version of Quartz. That’s why the method doesn’t exist in the Scheduler interface you’re working with.

解决方案

1. 升级Quartz到2.x及以上版本

First, you’ll need to replace the outdated quartz-all-1.6.1.jar with a modern 2.x release (I recommend a stable version like 2.3.2 or newer—avoid bleeding-edge versions if you need production stability).

  • If you’re using Maven, update your dependency in pom.xml:
    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>2.3.2</version>
    </dependency>
    
  • For Gradle, update your build.gradle:
    implementation 'org.quartz-scheduler:quartz:2.3.2'
    
    Note: Quartz 2.x split the monolithic quartz-all jar into smaller modules, so you’ll use the core quartz artifact instead of quartz-all.

2. 修复API兼容性问题

Quartz 2.x made significant API changes from 1.x, so you’ll need to adjust your code where it interacts with Quartz:

  • 任务/触发器创建: 1.x使用直接实例化,2.x改用Builder模式。示例:
    // Quartz 1.x (旧写法)
    JobDetail job = new JobDetail("jobName", "groupName", MyJob.class);
    // Quartz 2.x (新写法)
    JobDetail job = JobBuilder.newJob(MyJob.class)
        .withIdentity("jobName", "groupName")
        .build();
    
  • 监听器注册: 现在可以用getListenerManager()注册监听器,替代1.x的旧方法。示例:
    scheduler.getListenerManager().addJobListener(new MyJobListener());
    
  • 包结构变化: 部分类迁移了包路径——比如ListenerManager仍在org.quartz下,但其他工具类可能有变动。如果遇到编译错误,可参考Quartz 2.x文档确认类的具体位置。

3. 清理冲突依赖

有时候项目中的其他库会间接引入旧版本的Quartz(比如某些企业框架或遗留依赖)。用构建工具检测并排除这些冲突:

  • 在Maven中,给引入旧Quartz的依赖添加排除规则:
    <dependency>
        <groupId>some-legacy-library</groupId>
        <artifactId>legacy-artifact</artifactId>
        <version>x.y.z</version>
        <exclusions>
            <exclusion>
                <groupId>org.quartz-scheduler</groupId>
                <artifactId>quartz</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
  • 在Gradle中,使用exclude:
    implementation('some-legacy-library:legacy-artifact:x.y.z') {
        exclude group: 'org.quartz-scheduler', module: 'quartz'
    }
    

最后检查

更新jar包并调整代码后,执行完整构建并测试调度逻辑,确保监听器、任务和触发器都能正常工作。API变更容易有遗漏,注意留意编译或运行时的警告信息。

内容的提问来源于stack exchange,提问作者Sandeep Pandey

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 04:51:27