When

uses Quartz in Spring Boot, Bean is generally referred to in JOB, which is automatically managed by Job Factory.

Spring has its own Schedule timing task. When it is used in Spring boot, it can not manage JOB dynamically, so Quartz is used to implement it.

configuring Quartz:

 import java.io.IOException in Spring Boot; import java.util.Properties; import org.springframework.beans.factory.annotation.Autowired; .Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.quartz.SchedulerFactoryBean; @Configuration @EnableScheduling public. Ass QuartzSchedule {@Autowired private MyJobFactory myJobFactory; @Bean public SchedulerFactoryBean schedulerFactoryBean () throws IOException {] StartupDelay (20); / / / / loaded quartz data source configuration factory.setQuartzProperties (quartzProperties ()); / / / / custom Job Factory for Spring injection factory.setJobFactory (myJobFactory); return factory;} / * * loading quartz data source configuration * 
 Ception * / @Bean public Properties quartzProperties () throws IOException {PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean ()); Turn propertiesFactoryBean.getObject ();}} 

needs to redefine a Job Factory:

 @Component public, in order to use Spring managed Bean in JOB; A @Override protected Object createJobInstance (TriggerFiredBundle bundle) throws Exception {/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / TriggerFiredBundle bundle) Then in the JOB, you can use the Bean 

 public class MyJob implements Job, Serializable {private]. Public void execute (JobExecutionContext context) throws JobExecutionException {someService.doSomething ();} 

under the code is to create JOB:

. ThIdentity (job.getJobName (), job.getJobGroup ()).Build (); jobDetail.getJobDataMap ().Put ("extdata", job.getExtData ()); / / / / expression scheduling builder CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule (job.getCronExpression ()) OnDoNothing (); / / / / / / / / build a trigger TriggerBuilder< CronTrigger> triggerBuilder = TriggerBuilder.newTrigger ().WithIdentity (triggerKey).WithSchedule (scheduleBuilder); if (job.getStartTime ()! =);} If (job.getEndTime ()! = null) {triggerBuilder.endAt (job.getEndTime ());} CronTrigger trigger = triggerBuilder.build (); scheduler.scheduleJob (jobDetail, trigger); / / / / / injected to the management class 

above is all the content of this article, hoping to be helpful to everyone's study Also, I hope you can support the home of the script.

that you may be interested in:


This concludes the body part

This paper fixed link:http://www.script-home.com/spring-boot-integrated-quartz-injection-into-spring-managed-classes.html | Script Home | +Copy Link

Article reprint please specify:Spring Boot integrated Quartz injection into Spring managed classes | Script Home

You may also be interested in these articles!