gpt4 book ai didi

java - Spring - Quartz 不执行作业类

转载 作者:行者123 更新时间:2023-11-30 07:52:51 26 4
gpt4 key购买 nike

我正在尝试使用 quartz 和 Spring 运行作业,但没有运行该作业,也没有在控制台上出现错误。该作业已保存在 mysql 中,但未运行。

我的配置是

  • Spring 4.0.6
  • quartz 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>

MyJob 类

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!!!");
}
}

主要测试类

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并且它工作了。

关于java - Spring - Quartz 不执行作业类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33127183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com