java - Quartz 调度程序在服务器启动时出现错误

标签 java cron quartz-scheduler crontrigger

我正在我的类 SchedulerJob 的 Web 应用程序中使用 quartz 调度,我正在从数据库获取数据并根据某些条件设置一些字段,但我收到以下错误

org.quartz.SchedulerException: JobStore class 'org.quartz.simpl.RAMJobStore' props could not be configured. [See nested exception: java.lang.NoSuchMethodException: No setter for  property 'driverDelegateClass,']

我有quartz.properties文件,我在其中定义了RAM作业,例如

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
org.quartz.jobStore.tablePrefix, 
org.quartz.jobStore.driverDelegateClass, 
org.quartz.jobStore.dataSource
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore

我的类(class)是

public class QuartzSchedulerListener implements ServletContextListener {

public void contextDestroyed(ServletContextEvent arg0) {
    //
}

public void contextInitialized(ServletContextEvent arg0) {

    JobDetail job = JobBuilder.newJob(SchedulerJob.class)
        .withIdentity("anyJobName", "group1").build();

    try {

        Trigger trigger = TriggerBuilder
          .newTrigger()
          .withIdentity("anyTriggerName", "group1")
          .withSchedule(
             CronScheduleBuilder.cronSchedule("0/10 * * * * ?"))
          .build();

        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        scheduler.start();
        scheduler.scheduleJob(job, trigger);

    } catch (SchedulerException e) {
        e.printStackTrace();
    }

}

}

每 10 秒触发一次

和一个 SchedulerJob 完成类似的工作

公共(public)类 SchedulerJob 实现 Job { 私有(private)静态最终 Logger LOGGER = LoggerFactory.getLogger(SchedulerJob.class);

@EJB
private Iinterface service;


public void execute(JobExecutionContext context)
    throws JobExecutionException {

    // fetch list from DB
    List<SampleClass> list= new ArrayList<SampleClass>();
    try {

        list= service.getData();
        LOGGER.info("after action cron");
    } catch (Exception e) {
        LOGGER.info("exception action cron");
        e.printStackTrace();
    } 

    DO some operation and update on this list


    System.out.println("Struts 2.3.4 + Quartz 2.1.5");

}

}

这是完整的堆栈跟踪

[#|2013-05-20T23:36:32.132+0530|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=10;_ThreadName=Thread-2;|org.quartz.SchedulerException: JobStore class 'org.quartz.simpl.RAMJobStore' props could not be configured. [See nested exception: java.lang.NoSuchMethodException: No setter for property 'driverDelegateClass,']
at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:874)
at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1502)
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4750)
at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:550)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5366)
at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2019)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:375)
at com.sun.enterprise.v3.server.ApplicationLoaderService.postConstruct(ApplicationLoaderService.java:219)
at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:131)
at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:78)
at com.sun.enterprise.v3.server.AppServerStartup.run(AppServerStartup.java:253)
at com.sun.enterprise.v3.server.AppServerStartup.doStart(AppServerStartup.java:145)
at com.sun.enterprise.v3.server.AppServerStartup.start(AppServerStartup.java:136)
at com.sun.enterprise.glassfish.bootstrap.GlassFishImpl.start(GlassFishImpl.java:79)
at com.sun.enterprise.glassfish.bootstrap.GlassFishDecorator.start(GlassFishDecorator.java:63)
at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiGlassFishImpl.start(OSGiGlassFishImpl.java:69)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain$Launcher.launch(GlassFishMain.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain.main(GlassFishMain.java:97)
at com.sun.enterprise.glassfish.bootstrap.ASMain.main(ASMain.java:55)

由以下原因引起:java.lang.NoSuchMethodException:没有属性“driverDelegateClass”的 setter 在org.quartz.impl.StdSchedulerFactory.setBeanProps(StdSchedulerFactory.java:1390) 在org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:872) ... 37 更多 |#]

请建议我在这里做错了什么

最佳答案

RamJobStore 没有属性 org.quartz.jobStore.driverDelegateClass。 此外,您的属性文件还包含您正在使用的作业存储类型的其他不正确的属性:

org.quartz.jobStore.tablePrefix,
org.quartz.jobStore.driverDelegateClass,
org.quartz.jobStore.dataSource.

为什么用逗号分隔? 您可以将quartz作业存储在内存中(通过使用RamJobStore)或保存到RDBMS(通过使用JobStoreTx)。因此,首先要自己决定您的情况需要什么样的存储。 quartz 网站上提供了每个案例的示例。

关于java - Quartz 调度程序在服务器启动时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16656007/

相关文章:

java - 为什么我的构造函数不能正常工作?

java - `+=` 运算符是否总是创建一个新的字符串对象?

Cron 表达式 - 每天两个不同的时间 (13 :30 and 17:40)?

java - Cron 表达式 : Run on specific time (1:30 pm , 15:24 pm) 仅适用于周一和周三

java - 如何更改 CronTrigger 中的 cron 表达式(quartz 2.2,spring 4.1)

java - 使用依赖注入(inject)连接多个配置类

java - 为什么 Java GUI JFrame 在不同的操作系统上大小不同?

macos - 如何仅在计算机连接到 Internet 后才执行错过的 cron 或 launchd 作业?

linux - 为什么这个 ftp get 命令在我的 shell 脚本中工作但在 cron 中失败

java - 如果失败则在给定时间内执行任务