In the application, since I converted it from the classic Spring webapp (deployed on a Tomcat system) to the Spring Boot application (V1.2.1), I ran into the problem that quartz-based scheduled tasks are not working anymore.
I plan these Quartz assignments as follows:
// My own Schedule object which holds data about what to schedule when Schedule schedule = scheduleService.get(id of the schedule); String scheduleId = schedule.getId(); JobKey jobKey = new JobKey(scheduleId); TriggerKey triggerKey = new TriggerKey(scheduleId); JobDataMap jobData = new JobDataMap(); jobData.put("scheduleId", scheduleId); JobBuilder jobBuilder = JobBuilder.newJob(ScheduledActionRunner.class) .withIdentity(jobKey) .withDescription(schedule.getName()) .usingJobData(jobData); JobDetail job = jobBuilder.build(); TriggerBuilder triggerBuilder = TriggerBuilder.newTrigger() .forJob(jobKey) .withIdentity(triggerKey) .withDescription(schedule.getName()); triggerBuilder = triggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule(schedule.toCronExpression())); Trigger trigger = triggerBuilder.build(); org.quartz.Scheduler scheduler = schedulerFactoryBean.getScheduler(); scheduler.scheduleJob(job, trigger);
ScheduledActionRunner :
@Component public class ScheduledActionRunner extends QuartzJobBean { @Autowired private ScheduleService scheduleService; public ScheduledActionRunner() { } @Override public void executeInternal(final JobExecutionContext context) throws JobExecutionException { SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); final JobDataMap jobDataMap = context.getMergedJobDataMap(); final String scheduleId = jobDataMap.getString("scheduleId"); final Schedule schedule = scheduleService.get(scheduleId); // here it goes BANG since scheduleService is null } }
ScheduleService is a classic Spring service that retrieves data from Hibernate. As I said above, this worked fine until I switched to Spring Boot.
When I implemented this code with the classic Spring application, SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); did the trick to take care of outsourcing the service.
What is needed to re-work in the Spring boot environment?
Edit:
In the end, I decided to abandon the use of Quartz in favor of Spring ThreadPoolTaskScheduler. The code has been greatly simplified and works as expected.
java spring spring-boot hibernate quartz-scheduler
yglodt
source share