Job exists in the database, can be dynamic additions and deletions, and recently encountered how to obtain the applicationcontext context of the problem. The workaround 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 this class key/value. Be able to get the corresponding spring context with the key defined by 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, and the ApplicationContext context can be obtained by passing in the context of the quartz through the Getapplicationcontext method. And then get the corresponding bean
Spring +quartz Get ApplicationContext context