最近在项目中用到 了Spring的JobDetailBean,可以在JobDetailBean中调用QuartzJobBean,可以通过jobDataAsMap传递参数:
如:QuartzJobBean的实例TestTimeOutJob :
import java.util.HashMap;
import java.util.Map;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class TestTimeOutJob extends QuartzJobBean {
private int id;
private String name;
public void setId(int id) {
this.id = id;
}
public void setname(String name) {
this.name = name;
}
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
try {
System.out.println("---------id: " + id);
System.out.println("---------name: " + name);
} catch (BeansException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
spring bean.xml中配置:
<bean id="testTimeOutJob" class="org.springframework.scheduling.quartz.JobDetailBean" scope="prototype">
<property name="jobClass" value="xx.xx.xx.TeployTimeOutJob"></property>
</bean>