【问题标题】:Quartz HelloJob石英 HelloJob
【发布时间】:2011-06-09 14:58:40
【问题描述】:

我是 Quartz 的新手,我遇到了编译错误。我只是想让 HelloJob 根据 Quartz 的第 1 课为 Hello World 运行。我在声明 JobDetail 时遇到了错误:The method newJob(Class<? extends Job>) 类型为 JobBuilder 不适用于参数(类)”。

原来,代码在newJobnewTriggersimpleSchedule有3个错误

// define the job and tie it to our HelloJob class
JobDetail job = newJob(HelloJob.class)
    .withIdentity("job1", "group1")
    .build();

// Trigger the job to run now, and then repeat every 40 seconds
Trigger trigger = newTrigger()
    .withIdentity("trigger1", "group1")
    .startNow()
    .withSchedule(simpleSchedule()
            .withIntervalInSeconds(40)
            .repeatForever())            
    .build();

没有 JobBuilder.newJob(...)、TriggerBuilder.newTrigger(...)、SimpleScheduleBuilder.simpleSchedule(...)。与给出的示例不同,我继续添加导入并将类调用附加到 newJob、newTrigger 等前面,从而消除了 2/3 错误。但似乎错误仍然存​​在

 JobDetail job = JobBuilder.newJob(HelloJob.class)
        .withIdentity("job1", "group1")
        .build();

我也尝试过用

替换我的工作声明
JobDetail job = new JobDetail("job1", "group1", HelloJob.class);

但它以Cannot instantiate the type JobDetail 结尾,似乎有几个例子可以做到这一点。

非常感谢您的澄清,

谢谢!

【问题讨论】:

  • 你能发布课程“HelloJob”
  • 是的,在我的 HelloJob 中没有实现 Job。抱歉犯了一个愚蠢的错误!
  • 感谢您提出这个问题;我有同样的问题,很高兴找到这个解决方案。石英文档有点错误似乎很遗憾。

标签: java quartz-scheduler


【解决方案1】:

你需要有这行代码:

import static org.quartz.JobBuilder.*;

然后 in 应该可以工作。希望。

编辑: 并确保“HELLOJOB”实现工作!!

那里。

【讨论】:

    【解决方案2】:

    您需要为 helloJob 示例添加以下四个导入以适用于 quart 2.2.x

    import org.quartz.SimpleTrigger;
    import static org.quartz.JobBuilder.newJob;
    import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
    import static org.quartz.TriggerBuilder.newTrigger;
    

    【讨论】:

      【解决方案3】:

      给你:

      public class HelloJob implements Job {
      
      @Override
      public void execute(JobExecutionContext arg0) throws JobExecutionException {
          System.out.println("Simple Exapmle");
      
       }
      }
      

      【讨论】:

        【解决方案4】:

        Quartz 2 API 与 Quartz 1(1.5、1.6 和 1.7)类 JobDetail 有很大不同{ }

        石英-1.6.6: http://javasourcecode.org/html/open-source/quartz/quartz-1.6.6/org/quartz/JobDetail.html

        石英 2:

        public interface JobDetail extends Serializable, Cloneable {
        }
        
        // we have to create JobDetail in the below way.
        JobDetail job = newJob(HelloJob.class)
        
        // we have to create Trigger in the below way.
        Trigger trigger = newTrigger()
        

        别忘了导入下面的

        import static org.quartz.JobBuilder.*;
        import static org.quartz.TriggerBuilder.*;
        

        【讨论】:

          【解决方案5】:

          1-

          Quartz 提供定义领域特定语言的“构建器”类

          您可以通过以下方式导入缺少的 DSL:

          import static org.quartz.JobBuilder.*;
          import static org.quartz.TriggerBuilder.*;
          import static org.quartz.SimpleScheduleBuilder.*;
          

          2- 确保 HelloJob 类实现 org.quartz.Job 而不是任何其他作业:

            public class HelloJob implements org.quartz.Job{
          
               public void execute(JobExecutionContext context) throws JobExecutionException{
                 System.out.println("Hello!  HelloJob is executing.");
               }
            }
          

          您可以在quartz 文档中找到tutorial

          【讨论】:

            【解决方案6】:

            在这个website 上有这个例子的更详细的描述。在那里,您可以找到导入所需的库,以及 HelloJob 类中的作业实现。

            【讨论】:

              【解决方案7】:

              您必须使用Job 接口实现HelloJob.class

              使用

              import org.quartz.Job;
              
              public class HelloJob implements Job {
              
              }
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2012-11-04
                • 2012-07-18
                • 1970-01-01
                • 2021-05-18
                • 2011-05-01
                • 2018-10-13
                相关资源
                最近更新 更多