好人。我正在尝试在一个由 maven 管理的非常简单的项目中使用石英和 spring。所以在 mycron 作业类所在的模块中,我在其中包含了一个 java 主类,只是为了查看作业输出一些文本和新日期。这是我的弹簧配置:
<!--Scheduling-->
<!--Job-->
<bean id="projUpdater" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.myproject.utilscheduling.quartz.ProjUpdaterCronImpl" />
</bean>
<!---End of Jobs-->
<!--Triggers-->
<bean id="regularUpdateTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="projUpdater"/>
<property name="cronExpression" value="30 1 * * * ?"/>
</bean>
<!--End ofTriggers-->
<!--Scheduler Factory-->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="regularUpdateTrigger"/>
</list>
</property>
</bean>
<!--End of Scheduler Factory-->
<!--End of Scheduling-->
这是工作类
public class ProjUpdaterCronImpl extends QuartzJobBean {
public ProjUpdaterCronImpl() {
}
protected void executeInternal (JobExecutionContext ctx) throws JobExecutionException {
System.out.println("[JOB] " + new Date() + "hello");
}
}
这是主要课程
public class NewMain {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("starting job");
}
}
所以据我了解,这项工作将在 1mn30s 之后开始并发布在控制台上。我错了。我遇到了几个或我解决的错误,所以我可以安全地假设 spring 配置文件中没有错误,因为没有任何时间构建和运行。那么我做错了什么或者我忘了做什么?
第二个问题,因为我强迫自己采用测试驱动的方式,我将如何测试 cron 作业类?谢谢阅读