spring boot使用quartz定时器启动报错,但是定时器正常运行



spring boot添加quartz定时器报错但是定时器正常运行

[DEBUG] 2017-11-29 11:28:13,533 org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor - Could not find default TaskScheduler bean

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.scheduling.TaskScheduler' available


检查之后发现

,Spring的定时任务调度器会尝试获取一个注册过的 task scheduler来做任务调度,它会尝试通过BeanFactory.getBean的方法来获取一个注册过的scheduler bean,获取的步骤如下:

1.尝试从配置中找到一个TaskScheduler Bean

2.寻找ScheduledExecutorService Bean

3.使用默认的scheduler

前两步,如果找不到的话,就会以debug的方式抛出异常,分别是:

logger.debug("Could not find default TaskScheduler bean", ex);
logger.debug("Could not find default ScheduledExecutorService bean", ex);

所以,日志中打印出来的两个异常,根本不是什么错误信息,也不会影响定时器的使用,只不过是spring的自己打印的一些信息罢了,不过没搞明白,为什么非要用异常的方式打出来,估计是为了看这清晰点吧。也或者,这里面有一些重要的信息需要提示开发者。具体是什么原因,只能有机会进一步再去了解了。

下面贴上我的定时器代码。仅供记录参考:

package com.tt.pwp.report.quartz;

import com.tt.pwp.report.ws.client.request.PlatFormConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by Administrator on 2017/11/24 0024.
 */
@Component
@Configurable
@EnableScheduling
public class ReportDataQuartz {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private PlatFormConfig ymlConfig;
    @Scheduled(fixedRate = 500000) // 每分5m行一次
    public void doReportOneDay() throws Exception {
        System.out.println("执行调度任务:"+new Date());
    }
//    public void doReportTwoDays() throws Exception {
//        System.out.println("执行调度任务:"+new Date());
//    }
//    public void doReportThereDays() throws Exception {
//        System.out.println("执行调度任务:"+new Date());
//    }
//    public void doReportFourDays() throws Exception {
//        System.out.println("执行调度任务:"+new Date());
//    }
//    public void doReportFiveDays() throws Exception {
//        System.out.println("执行调度任务:"+new Date());
//    }
//    public void doReportSixDays() throws Exception {
//        System.out.println("执行调度任务:"+new Date());
//    }
//    public void doReportOneWeek() throws Exception {
//        System.out.println("执行调度任务:"+new Date());
//    }
//    public void doReportOneMonth() throws Exception {
//        System.out.println("执行调度任务:"+new Date());
//    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值