spring定时任务之quartz基于xml开发

定时器配置完成抛出异常
1.SchedulerException: Jobs added with no trigger must be durable 
需要在 在jobDeatailsBean 中加一句 <property name="durability" value="true" />
 2.DateSource name is not set  说明quartz的配置文件中没有配置链接数据库的信息
1 编写业务类,该类继承了org.quartz.Job,主要的逻辑在execute方法中编写
2 配置spring的applicationContext.xml文件
    2.1 配置任务JobDetailBean
    2.2配置触发器 CronTriggerBean
    2.3配置调度器  SchedulerFactoryBean

3 所需要的jar包:
         spring.jar,quartz.jar,commons-logging-1.0.4.jar,commons-dbcp-1.2.2.jar,commons-pool-1.3.jar
4 把quartz.properties放到类路径下

配置文件代码 写入spring.xml中
<context:component-scan base-package="com.fac.timer" />
 <bean id="toPtAccountTime" class="com.fac.timer.ToPtAccountTime" /> 
    <bean name="reportTask" 
        class="org.springframework.scheduling.quartz.JobDetailFactoryBean"> 
        <property name="jobClass" value="com.fac.timer.ToPtAccountTime" /> 
        <property name="durability" value="true" />
    </bean> 
    <!-- 触发器 --> 
    <bean id="cronTrigger" 
        class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 
        <!-- 指向我们的任务 --> 
        <property name="jobDetail" ref="reportTask" /> 
        <!--  每天下午16点10分到55分,每分钟运行一次 --> 
        <property name="cronExpression" value="0 10-55 16 * * ?" /> 
    </bean> 
    <!-- 调度器  --> 
    <bean 
        class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
        <property name="triggers"> 
            <list> 
                <!--  触发器列表 --> 
                <ref bean="cronTrigger" /> 
            </list> 
        </property> 
        <property name="configLocation" value="classpath:config/quartz.properties" />  
    </bean>  
  
配置文件的内容、
#============================================================================
# Configure Main Scheduler Properties 
#============================================================================
org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
#============================================================================
# Configure ThreadPool 
#============================================================================
#org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
#org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
#============================================================================
# Configure JobStore 
#============================================================================
#org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
#org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
org.quartz.jobStore.misfireThreshold = 60000
#org.quartz.jobStore.useProperties = false
#org.quartz.jobStore.tablePrefix = QRTZ_
#org.quartz.jobStore.dataSource = myDS
#org.quartz.jobStore.isClustered = true
#org.quartz.jobStore.clusterCheckinInterval = 15000
#============================================================================
# Configure DataSource
#============================================================================
org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL = jdbc\:mysql\://192.168.1.254\:3306/p2pv1?useUnicode\=true&characterEncoding\=utf8
org.quartz.dataSource.myDS.user = admin
org.quartz.dataSource.myDS.password = P@ssword\!
org.quartz.dataSource.myDS.maxConnections = 10 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值