The spring injection problem of quartzy

Source: Internet
Author: User

<!--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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.