<!--quartz timer, Timer class--self-used class--<bean id= "Jobdetailfactorybean" class= " Org.springframework.scheduling.quartz.JobDetailFactoryBean "> <property name=" jobclass "value=" Com.myk.oe.utils.QuartzTask "></property> </bean> <!--Configure execution time and rules--<bean id=" Quartztask " class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean" > <property name= "jobdetail" ref= "Jobde Tailfactorybean "></property> <!--5 Seconds--<property name=" cronexpression "value=" 0 /5 * * * * *? ></property> </bean> <!--to inject beans into the timer class--<bean id= "jobfactory" class= "Com.myk.oe.quart Z.util.jobfactory "></bean> <!--General Management class if lazy-init= ' false ' then the container starts executing the scheduler--<bean class=" Org.spri Ngframework.scheduling.quartz.SchedulerFactoryBean "lazy-init=" false "> <property name=" triggers "> <list> <ref bean= "Quartztask"/><!--Tasks-</list> </property> <property name= "jobfactory" ref= "Jobfactory" > </property> <property name= "Autostartup" value= "true"/><!--auto-start </bean>
A related class that defines a timed task, which reports null pointer exceptions when invoking DAO or service in a class.
Add annotations on the class of the timed task @disallowconcurrentexecution to inject service and DAO.
@DisallowConcurrentExecution Public classQuartztaskextendsquartzjobbean{@Resource (name= "Appointmentserviceimpl") PrivateAppointmentservice Appointmentservice;//This is the service class@Overrideprotected voidexecuteinternal (jobexecutioncontext context)throwsjobexecutionexception {List<Appointment> appointments = appointmentservice.getappointments ();//Get DataSystem.err.println (Appointments); }}
The spring injection problem of quartzy