[英]quartz integration with spring,null pointer exception
i am trying to integrate quartz with spring, a file location is passed to the JobCSVfile class from a jsp page but it is not taking that location and showing null pointer exception. 我正在尝试将石英与Spring集成,文件位置从jsp页面传递到JobCSVfile类,但它没有采用该位置并显示空指针异常。 And i also want to shedule the timing from the jsp page i dont know how to dothat since i am using the trigurring details in the applicationcontext.xml
而且我也想摆脱jsp页面的时间,因为我在applicationcontext.xml中使用了琐碎的细节,所以我不知道该怎么做
applicationcontext.xml applicationcontext.xml
<bean id="jobCSVfile"
class="com.vxl.appanalytix.dataload.quartz.JobCSVfile">
</bean>
<bean id="JobA" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.vxl.appanalytix.dataload.quartz.JobCSVfile" />
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="5" />
</map>
</property>
</bean>
<bean id="cronTriggerJobA" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="JobA" />
<property name="cronExpression" value="0/5 * * * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="JobA" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronTriggerJobA" />
</list>
</property>
</bean>
with out sheduling in the applicationcontext.xml can we do it in any other way? 不用在applicationcontext.xml中保留代码,我们可以采用其他任何方式吗?
i can show you what i have done, i use java not jsp (i don't know jsp) 我可以告诉你我做了什么,我使用Java而不是JSP(我不知道JSP)
first i created my job interface: 首先,我创建了我的工作界面:
public interface JobI {
void execute(Object[] args);
}
i needed to have same executable method for each job 我需要为每个作业使用相同的可执行方法
then create job and beanify it 然后创建作业并将其豆化
public class SimpleJob implements JobI {
@Override
public void execute(Object[] args) {
for (Object o : args) {
// String[] array = o.toString().split("=");
System.out.println(o.toString());
}
}
}
// context file //上下文文件
<bean id="simpleJob" class="uk.co.utel.tcds.system.schedule.jobs.SimpleJob" />
now just create class where you will be adding new jobs ie JobController 现在只需创建类,您将在其中添加新作业,即JobController
public JobController{
private final StdScheduler scheduler;
public JobController(StdScheduler scheduler){
this.scheduler=scheduler;
}
public void addJob(String cronExpr){
CronTrigger trigger = new CronTrigger("name","group");
trigger.setCronExpression(cronExpr));
scheduler.scheduleJob(getJobDetails(), trigger);
}
public JobDetails getJobDetails(){
final JobI jobBean = (JobI) applicationContext.getBean("SimpleJob");
final MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
jobDetail.setTargetObject(jobBean);
jobDetail.setTargetMethod("execute");
jobDetail.setName("name");
jobDetail.setGroup("group");
return (JobDetail) jobDetail.getObject();
}
}
// context file //上下文文件
<bean id="jobController" class="JobController">
<constructor-arg name="scheduler" ref="scheduler" />
</bean>
all what you need is to add id to scheduler 您所需要做的就是向调度程序添加ID
<bean id="scheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
.....
</bean>
now when you want to use it with jsp, all what you need is pass jobController bean to your script and call addJob method 现在,当您想将其与jsp一起使用时,所需要做的就是将jobController bean传递给脚本并调用addJob方法
and right, i almost forgot, in different version of quartz might be different way to create JobDetail
and Trigger
objects 正确,我几乎忘了,在不同版本的石英中,创建
JobDetail
和Trigger
对象的方式可能不同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.