Spring - Quartz 不执行作业类
Spring - Quartz no execute jobclass
我正在尝试 运行 使用 quartz 和 spring 的作业,但没有 运行 作业并且不会在控制台上出现错误。作业保存在 mysql 中,但未保存在 运行 中。
我的配置是
- spring 4.0.6
- 石英 2.2.1
applicationContext.xml
<bean id="scheduler" name="scheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
scope="singleton">
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.scheduler.instanceName">MyClusteredScheduler</prop>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
<prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.jobStore.clusterCheckinInterval">20000</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="*****" />
<property name="password" value="*****" />
</bean>
我的工作class
public class MyJob implements Job, Serializable{
private static final long serialVersionUID = -1750295779628942902L;
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("run job run!!!");
}
}
主要测试class
public static void main(String[] args) {
ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
StdScheduler stdScheduler= (StdScheduler) context.getBean("scheduler");
MyJob myJob= (MyJob) context.getBean("myJob");
try {
JobDetail jobDetail = JobBuilder.newJob(MyJob.class).withIdentity("triggerUno10").build();
Trigger trigger= TriggerBuilder.newTrigger().withIdentity("triggerUno10").withSchedule(
CronScheduleBuilder.cronSchedule("0/5 * * * * ?")).forJob(jobDetail).build();
stdScheduler.start();
stdScheduler.scheduleJob(jobDetail, trigger);
} catch (Exception e) {
e.printStackTrace();
}
}
问题是 quartz 版本在某种程度上不能很好地与 spring4.0.6 一起工作,为了解决这个问题,我将 quartz 降级到 2.1.7 并且它可以工作。
我正在尝试 运行 使用 quartz 和 spring 的作业,但没有 运行 作业并且不会在控制台上出现错误。作业保存在 mysql 中,但未保存在 运行 中。
我的配置是
- spring 4.0.6
- 石英 2.2.1
applicationContext.xml
<bean id="scheduler" name="scheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
scope="singleton">
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.scheduler.instanceName">MyClusteredScheduler</prop>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
<prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.jobStore.clusterCheckinInterval">20000</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="*****" />
<property name="password" value="*****" />
</bean>
我的工作class
public class MyJob implements Job, Serializable{
private static final long serialVersionUID = -1750295779628942902L;
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("run job run!!!");
}
}
主要测试class
public static void main(String[] args) {
ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
StdScheduler stdScheduler= (StdScheduler) context.getBean("scheduler");
MyJob myJob= (MyJob) context.getBean("myJob");
try {
JobDetail jobDetail = JobBuilder.newJob(MyJob.class).withIdentity("triggerUno10").build();
Trigger trigger= TriggerBuilder.newTrigger().withIdentity("triggerUno10").withSchedule(
CronScheduleBuilder.cronSchedule("0/5 * * * * ?")).forJob(jobDetail).build();
stdScheduler.start();
stdScheduler.scheduleJob(jobDetail, trigger);
} catch (Exception e) {
e.printStackTrace();
}
}
问题是 quartz 版本在某种程度上不能很好地与 spring4.0.6 一起工作,为了解决这个问题,我将 quartz 降级到 2.1.7 并且它可以工作。