- 浏览: 622077 次
- 性别:
- 来自: 北京
最新评论
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!--起动Bean--> <bean id="z" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="cronReportTrigger"/> </list> </property> </bean> <!--实际的工作Bean--> <bean id="courseService" class="com.spring.helloworld.CourseService"></bean> <!--jobBean用于设定启动时运用的Bean与方法--> <bean id="scheduledReportJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="courseService"/> </property> <property name="targetMethod"> <value>sendCourseEnrollmentReport</value> </property> </bean> <!--定时器设定起动频率&启动时间我设的是每5秒起动一次 (0 0 4 * * ?每日四点起动....)--> <bean id="cronReportTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"><ref bean="scheduledReportJobDetail"/> </property> <property name="cronExpression"><value>10,15,20,25,30,35,40,45,50,55 * * * * ?</value> </property> </bean> </beans>
测试
package com.spring.helloworld; import java.io.FileNotFoundException; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.FileSystemResource; import com.spring.hellow.LogInit; import com.spring.hellow.QuestException; public class TaskApp { public static void main(String[] args) throws BeansException, FileNotFoundException, QuestException, InterruptedException { new LogInit("WEB-INF/classes/com/spring/helloworld/log4j.properties"); BeanFactory factory = new XmlBeanFactory(new FileSystemResource( "WEB-INF/classes/" + "com/spring/helloworld/" + "helloworld.xml")); factory.getBean("z");//为什么必须用这个方法触发呢不触发为什么不行呢? } }
评论
9 楼
fly_ever
2009-11-05
这是我的一个测试,我配的2个任务。
spring 的配置:
运行时,首先我采用MainTest 测试
发现程序打印end后就结束了。
然后我用Main测试,可以正常执行。
job类的内容为:
spring 的配置:
<!-- 与quartz有关的设置 --> <bean id="billJob" class="test.BillReliabilityJob"/> <bean id="exceptionJob" class="test.ExceptionJob"/> <bean id="billJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="billJob"/><!-- 调用的Job类 --> </property> <property name="targetMethod"> <value>run</value><!-- 调用的类中的方法 --> </property> </bean> <bean id="exceptionJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="exceptionJob"/><!-- 调用的Job类 --> </property> <property name="targetMethod"> <value>run</value><!-- 调用的类中的方法 --> </property> </bean> <bean id="billRunTime" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="billJobTask"/> </property> <property name="cronExpression"> <value>0/5 * * * * ?</value> </property> </bean> <bean id="ExceptionRunTime" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="exceptionJobTask"/> </property> <property name="cronExpression"> <value>10 * * * * ?</value> </property> </bean> <!-- 总管理类,如果lazy-init='false',则容器启动时就会执行调度程序--> <!-- 如果lazy-init='true',则需要实例化该bean才能执行调度程序 --> <bean id="billStartQuartz" lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="billRunTime"/> <ref bean="ExceptionRunTime"/> </list> </property> </bean>
运行时,首先我采用MainTest 测试
public class MainTest extends TestCase { public void testJob(){ System.out.println("start"); ApplicationContext context = new FileSystemXmlApplicationContext( "./config/spring.xml"); System.out.println("end"); } }
发现程序打印end后就结束了。
然后我用Main测试,可以正常执行。
public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("start"); ApplicationContext context = new FileSystemXmlApplicationContext( "./config/spring.xml"); System.out.println("end"); } }
job类的内容为:
public class ExceptionJob { public void run(){ System.out.println("ExceptionJob running"); } }
8 楼
抛出异常的爱
2009-11-05
fly_ever 写道
很奇怪,在main方法中能正常运行,
而在测试类中,即继承TestCase的类中写一个方法,运行上述代码,则启动不了调度。
这是为什么呢?
而在测试类中,即继承TestCase的类中写一个方法,运行上述代码,则启动不了调度。
这是为什么呢?
最好不要测试Quartz本身...
PS:你可以把有问题的代码发上来看看.
7 楼
fly_ever
2009-11-05
很奇怪,在main方法中能正常运行,
而在测试类中,即继承TestCase的类中写一个方法,运行上述代码,则启动不了调度。
这是为什么呢?
而在测试类中,即继承TestCase的类中写一个方法,运行上述代码,则启动不了调度。
这是为什么呢?
6 楼
抛出异常的爱
2009-05-12
jdk的版本
eclipse版本 project -> javacompiler的jdk版本
tomcat jdk 版本...
Quarzt已经配置好 tomcat 5.*启动报错 大佬 帮忙看下
严重: Error listenerStart
2009-5-8 16:00:39 org.apache.catalina.core.StandardContext start
严重: Context [/irdpcms] startup failed due to previous errors
eclipse版本 project -> javacompiler的jdk版本
tomcat jdk 版本...
12616383 写道
Quarzt已经配置好 tomcat 5.*启动报错 大佬 帮忙看下
严重: Error listenerStart
2009-5-8 16:00:39 org.apache.catalina.core.StandardContext start
严重: Context [/irdpcms] startup failed due to previous errors
5 楼
12616383
2009-05-08
Quarzt已经配置好 tomcat 5.*启动报错 大佬 帮忙看下
严重: Error listenerStart
2009-5-8 16:00:39 org.apache.catalina.core.StandardContext start
严重: Context [/irdpcms] startup failed due to previous errors
代码:
严重: Error listenerStart
2009-5-8 16:00:39 org.apache.catalina.core.StandardContext start
严重: Context [/irdpcms] startup failed due to previous errors
代码:
<!--配置一个Job--> <bean id="testJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass"> <value>com.zfsoft.irdpcms.action.QuartzJob</value> </property> <property name="jobDataAsMap"> <map> <entry key="pringThing"> <value>this is the first Quarzt</value> </entry> <entry key="printName"> <value>leo</value> </entry> </map> </property> </bean> <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> <property name="jobDetail"> <ref bean="testJobDetail"/> </property> <property name="startDelay"> <value>10</value> </property> <property name="repeatInterval"> <value>2000</value> </property> <property name="repeatCount"> <value>20</value> </property> </bean> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="autoStartup"> <value>true</value> </property> <property name="triggers"> <list> <ref bean="simpleTrigger"/> </list> </property> </bean>
4 楼
抛出异常的爱
2008-07-15
谢谢
3 楼
sbe_steels
2008-07-05
在web.xml配置spring的监听器就可以,如果还要硬编码的形式来获取Scheduler,可能不能完全成为定时器,或则定时任务。
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
2 楼
julycool
2007-09-05
设置lazy-init为false
1 楼
Godlikeme
2006-12-24
factory.getBean("z");//为什么必须用这个方法触发呢不触发为什么不行呢?
因为这个bean没有加载,scheduler没有实例化。如果自定义scheduler,还需要显示调用scheduler.start().或者再配置文件中声明。
因为这个bean没有加载,scheduler没有实例化。如果自定义scheduler,还需要显示调用scheduler.start().或者再配置文件中声明。
发表评论
-
vlc 必要的参数
2021-08-31 17:18 0vlc.exe -vvv -Idummy "rt ... -
grafana+mysql 页面设计
2019-02-25 08:51 0前提 1。主要是SELECT 。 2。使用mysql ... -
测试用例到底怎么才值的写
2016-04-30 10:32 0有个方法是这样的 public function ... -
postman cookies登陆设置
2016-04-28 09:30 2006必须登陆才能测试的接口如何测试? 打开这个开关就可以共用coo ... -
将png 切成ios android能用的格式
2016-04-28 01:24 711由于要求不高找了个在线切图的工具 http://images. ... -
如何在原有系统中加入功能(一数据库)
2016-04-24 11:06 789第一步想办法把建表语句导入一powerdesginer ... -
php递归 格式化 数字类型
2016-04-20 12:35 761/** * 数字转日期递归 ... -
freemind 怎么处理成为word
2015-06-11 19:37 16写文章用freemind打了一个草稿. 先导出成为htm ... -
架构师之路(工欲善其事,必先利其器)纸牌屋
2014-03-27 06:48 0起因:小胖的一个征集实现过程 https://gist.git ... -
油猴对抗一般广告
2012-11-14 00:07 1856看小说 好多好多的广告是必然的.. 所以 去掉iframe 去 ... -
回答一些很有共性的东西
2011-02-24 21:24 5550我作软件第二第三年时 ... -
粗糙的object打印日志用....
2010-11-04 18:40 2143function logJquery(o){ ... -
拳皇连招
2010-09-29 13:46 2343从列表中找到录入的后N位 class KOFTest { ... -
一个activeX方法 刚刚发现
2010-09-14 19:14 1485解答:此题 http://www.iteye.com/prob ... -
[反例]超短代码,意义不明
2010-08-19 17:49 1537public String logout(HttpServl ... -
站读帝
2010-07-26 09:29 1283http://www.hudong.com/wiki/%E7% ... -
不要重复发明轮子
2010-07-06 17:20 2139一直以为不要重复发明轮子的意义很简单. 今天看了人件.... ... -
答复: 不用判断语句求俩数中的大(或者小)数
2010-05-31 12:55 2087跳大神也是一种艺术: public class MaxMin ... -
集合合并
2010-05-28 10:15 1921用于时间表的合并 时间段的合并工作. public cla ... -
删除重名的记录
2010-04-05 23:04 1906面试看到这种题。。。。。 我估计考官的正确答案有可能是错的 所 ...
相关推荐
spring3 配置quartz定时任务的使用。一个小例子。可直接运行Test.java。就可以启动定时任务。每10秒钟执行一次,可以根据自己配置。
Spring集成quartz跑定时任务实例 自己写的例子并为实现job 有测试的主函数,请参考...springCon.quartz文件夹下 为对上诉博客理解透彻 结合spring看其配置的相关信息 就可以明白。
Spring+quartz 一个简单的 定时任务的例子,希望能对大家的学习有帮助。 最后,附:cronExpression配置说明 字段 允许值 允许的特殊字符 秒 0-59 , - * / 分 0-59 , - * / 小时 0-23 , - * / 日期 1-31 , - *...
Quartz spring配置 简单例子,
spring3 配置quartz定时任务的使用。一个小例子。可直接运行Test.java。就可以启动定时任务。
我自己亲自测试过的例子,spring quartz定时器的简单配置和使用,保证成功运行
看了网上很介绍配置文章,感觉很乱。而且不一定能跑起来。现在我把我的demo上传来。已经跑过。请放心使用。但是jar包太大上传不上来。自己导一下spring的jar就可以了。务必是commons-collections-3.1.jar不然会报错...
spring3.2之后quartz和之前的定时服务配置稍有不同 在这里分享一个自己写的例子(代码、源码、jar包都齐全) 直接导入myeclipse即可
待完善。简单的例子,免费下载。参考http://www.meiriyouke.net/?p=82 谢谢原作者 也谢谢ZJ
本项目示例基于spring boot 最新版本(2.1.9)实现,Spring Boot、Spring Cloud 学习示例...多数Spring Boot应用只需要很少的Spring配置。 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Sprin
第4章:讲解如何在Spring配置文件中使用Spring 3.0的Schema格式配置Bean的内容,并对各个配置项的意义进行了深入的说明。 第5章:对Spring容器进行解构,从内部探究Spring容器的体系结构和运行流程。此外,我们...
6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点实施 ...
2.2.3 类包及Spring配置文件规划 2.3 持久层 2.3.1 建立领域对象 2.3.2 UserDao 2.3.3 LoginLogDao 2.3.4 在Spring中装配DAO 2.4 业务层 2.4.1 UserService 2.4.2 在Spring中装配Service 2.4.3 单元测试 2.5 展现层 ...
6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点...
此资源包括了java各中job:java基础job,quartz框架的job,spring scheduling job,spring +quartz 数据库配置
6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点...
第4章:讲解如何在Spring配置文件中使用Spring 3.0的Schema格式配置Bean的内容,并对各个配置项的意义进行了深入的说明。 第5章:对Spring容器进行解构,从内部探究Spring容器的体系结构和运行流程。此外,我们...
6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点运算 ...
6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点运算 ...
2.2.3 类包及Spring配置文件规划 2.3 持久层 2.3.1 建立领域对象 2.3.2 UserDao 2.3.3 LoginLogDao 2.3.4 在Spring中装配DAO 2.4 业务层 2.4.1 UserService 2.4.2 在Spring中装配Service 2.4.3 单元测试 2.5 展现层 ...