Job exists in the database, you can make dynamic additions and deletions, and recently encountered how to obtain the ApplicationContext context, the solution is as follows
Applicationcontext-quartz.xml
<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE beans Public "-//spring//dtd BEAN 2.0//en" "Http://www.springframework.org/dtd/spring-beans-2.0.dtd" >< beans> <bean name= "Quartzscheduler" class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" > <property name= "Applicationcontextschedulercontextkey" value= "Applicationcontextkey"/> < Property Name= "Configlocation" value= "classpath:quartz.properties"/> </bean></beans>
<!--Applicationcontextschedulercontextkey: It is org.springframework.scheduling.quartz.SchedulerFactoryBean that the spring context is stored in the context of the quartz in a key/value way, The corresponding spring context can be obtained with the key defined by the Applicationcontextschedulercontextkey -
The corresponding job task
public class Quartzjobbean implements JOB {/* (non-javadoc) * @see Org.quartz.job#execute ( Org.quartz.JobExecutionContext) */@Overridepublic void execute (jobexecutioncontext jobcontext) throws jobexecutionexception {String jobId = Jobcontext.getjobdetail (). GetDescription (); String serviceId = Jobcontext.gettrigger (). GetDescription (); ApplicationContext applicationcontext=null;try {applicationcontext=getapplicationcontext (jobContext);} catch ( Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} Webserviceservice Webserviceservice = (webserviceservice) applicationcontext.getbean ("WebServiceService"); Webservicepojo WebService = Webserviceservice.getwebservice (serviceId); Scheduleservice.schedule (Webservice.getnamespace (), Webservice.getservicename (), Webservice.getwsdlurl (), Webservice.getmethod ());} private static final String Application_context_key = "Applicationcontextkey";p rivate applicationcontext Getapplicationcontext (Jobexecutioncontext context) throws Exception {appliCationcontext Appctx = Null;appctx = (applicationcontext) Context.getscheduler (). GetContext (). Get (APPLICATION_ Context_key); if (appctx = = null) {throw new Jobexecutionexception ("No application context available in scheduler context F or key \ "" + Application_context_key + "\" ");} return appctx;}}The value of Application_context_key is the value configured in the first XML, which is passed into the context of the quartz through the Getapplicationcontext method to get the ApplicationContext context. And then get the corresponding bean.