使用Spring整合Quartz定时执行任务
在修改一个项目的工程中。发现任务竟然没有生成。多次查看这个项目。终于在spring的配置中发现了定时任务。
使用spring整合Quartz来定时执行某个类中的方法。。于是经过上网查资料,终于实验成功了。
1.首先导入了spring的jar包和quartz的jar包
在spring的配置文件中。
?
???把需要执行的类在spring中先声明。
?
?<bean id="autoCreateJob2" name="code"> <!-- 每天凌晨生成下日作业(autoCreateJob2的dayPlan1方法) -->
定义bean和bean中的方法: <bean id="dayPlan1" value="false" /> </bean>
<!-- 定义执行时间:每天2:30生成下日作业, 0 30 2 * * ? -->
复杂的定义时间: <bean id="cronTrigger" ref="dayPlan1"/> <property name="cronExpression" > <value>0 30 2 ? * *</value> </property> </bean>
?
?
最后触发:?
?
<bean lazy-init="false" autowire="no" name="code">String[] configs={"file:F:/java/hnmetatask/web/WEB-INF/conf/applicationContext_hibernate.xml"};ApplicationContext ac=new ClassPathXmlApplicationContext(configs);?
最后感谢以下提供资料的一些链接:
http://www.cnblogs.com/kay/archive/2007/11/02/947372.html
?
http://www.2cto.com/kf/201201/116956.html
?
http://blog.csdn.net/jerry_bj/article/details/6792864
?
?