码迷,mamicode.com
首页 > 编程语言 > 详细

springboot的Scheduled定时器不工作

时间:2018-08-31 19:34:32      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:led   ack   col   使用   ring   定时器   date()   ota   nts   

问题情况

使用springboot,使用注解方式启动定时器进行业务调度。

在入口类中加了注解如下:

package org.test.xyz;

@SpringBootApplication
@EnableScheduling
@ComponentScan(basePackages = {"org.test.abc"})
public class Test
{
    public static void main(String[] args)
    {
        SpringApplication.run(Test.class, args);
    }
}

 

定时器类如下:

package org.test.xyz;

@Component
public class Timer
{
    @Scheduled(fixedRate = 5000)
    public void test()
    {
        System.out.println("Time " + new Date().toString());
    }
}

 

springboot启动后,并没有按照预期结果打印:Time xxx 的日志。

 

分析结果

因为在入口类中使用了@ComponentScan注解,并且指定了basePackages,所以程序只会扫描指定的包路径下的Component类,其他位置的Component类不会进行扫描,从而不会启动定时器。

参考链接:https://blog.csdn.net/u014695188/article/details/52263903

 

springboot的Scheduled定时器不工作

标签:led   ack   col   使用   ring   定时器   date()   ota   nts   

原文地址:https://www.cnblogs.com/willdoop/p/9567139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!