如何在部署到JBoss的JAR文件中设置Quartz调度程序?

时间:2012-08-06 21:00:51

标签: jar jboss quartz-scheduler

我正在使用Quartz 2.1.1并且有一个JAR应用程序(注意,不是网络,所以我没有Spring)。我在JBoss 4.2.2上运行我的应用程序(不能改变这个)。我想安排我的工作每5分钟运行一次,但不想通过静态块创建调度程序。反正它似乎没有用。在我的Job课程中,我有......

static {
    LOG.info("Started static process orders job at " + (new java.util.Date()).toString());

    final JobDetail job = JobBuilder.newJob(ProcessOrdersJob.class).withIdentity("processOrdersJob", "group1").build();

    final Trigger trigger = TriggerBuilder
            .newTrigger()
            .withIdentity("processOrdesrTrigger", "group1")
            .withSchedule(
                    CronScheduleBuilder
                            .cronSchedule("0 5,10,15,20,25,30,35,40,45,50,55 * * * ?"))
            .build();

    Scheduler scheduler;
    try {
        scheduler = new StdSchedulerFactory().getScheduler();
        scheduler.start();
        scheduler.scheduleJob(job, trigger);
    } catch (SchedulerException e) {
        LOG.error(e.getMessage(), e);
        e.printStackTrace(System.err);
    }
} // static

但它似乎没有运行(日志从不包含信息消息)。有没有人知道在我的JAR中配置Quartz作业以更灵活地部署到JBoss?

谢谢, -

编辑:我尝试了Rosdi的建议,将我的Maven构建使用的Quartz恢复为1.5.2(与JBoss安装的版本相同),但是唉,得到了异常

javax.ejb.EJBTransactionRolledbackException: java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object;
    at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
    at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
    at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:249)
    at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
    at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
    at $Proxy113.execute(Unknown Source)
    at org.jboss.resource.adapter.quartz.inflow.QuartzJob.execute(QuartzJob.java:57)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object;
    at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:174)
    at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
    ... 11 more
Caused by: java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object;
    at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.<clinit>(BeanValidationIntegrator.java:53)
    at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:46)
    at org.hibernate.service.internal.BootstrapServiceRegistryImpl.<init>(BootstrapServiceRegistryImpl.java:80)
    at org.hibernate.service.internal.BootstrapServiceRegistryImpl.<init>(BootstrapServiceRegistryImpl.java:57)
    at org.hibernate.service.ServiceRegistryBuilder.<init>(ServiceRegistryBuilder.java:76)
    at org.mainco.subco.dido.service.AbstractServiceProvider.getSessionFactory(AbstractServiceProvider.java:67)
    at org.mainco.subco.dido.service.AbstractServiceProvider.initServices(AbstractServiceProvider.java:118)
    at org.mainco.subco.dido.quartz.ProcessOrdersJob.execute(ProcessOrdersJob.java:92)
    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 org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)

1 个答案:

答案 0 :(得分:0)

这是我用于JBoss 5的内容,我不知道它是否适用于JBoss 4。

package whatever;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;

import org.jboss.ejb3.annotation.Depends;
import org.jboss.ejb3.annotation.ResourceAdapter;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@MessageDriven(activationConfig = {@ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "0/30 * * * * ?")})
@ResourceAdapter("quartz-ra.rar")
@Depends({
"jboss.ejb:service=EJBTimerService""})
public class MyClass implements StatefulJob {

private static final Logger log = LoggerFactory.getLogger(MyClass.class);

public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    log.debug("Job started at: " + new Date());
    this.process();
    log.debug("Job completed at: " + new Date());
}

private void process() {
    //do whatever you want to do
}

}