Search code examples
javaspringquartz-scheduler

Spring NoClassDefFoundError


I'm trying to rewrite my Quartz task scheduler code (running on a TomCat webserver) to use Spring. Using Quartz only the code runs fine:

Scheduler scheduler = new StdSchedulerFactory().getScheduler();

JobDetail job1 = JobBuilder.newJob(TestJob1.class).withIdentity(JOB_NAME_1, GROUP_TEST).build();

Trigger indefiniteTrigger = TriggerBuilder.newTrigger().withIdentity(TRIGGER_NAME_INDEFINITE, GROUP_TEST)
    .withSchedule(
            SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(3000).repeatForever())
    .build();

scheduler.scheduleJob(job1, indefiniteTrigger);

scheduler.start();

Trying to include Spring with the following code:

SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();

JobDetailFactoryBean job = new JobDetailFactoryBean();
job.setJobClass(TestSpringJob.class); //TestSpringJob class extends QuartzJobBean
job.setName("job");

SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
trigger.setJobDetail(job.getObject());
trigger.setRepeatInterval(3000);

schedulerFactory.setTriggers(trigger.getObject());
schedulerFactory.start();

Running the app with the Spring code produces

java.lang.ClassNotFoundException: org.springframework.transaction.TransactionException

What is wrong with the Spring code?


Solution

  • you are missing spring transaction package http://mvnrepository.com/artifact/org.springframework/spring-tx