Spring Scheduler不起作用 [英] Spring Scheduler does not work

查看:551
本文介绍了Spring Scheduler不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对基于Spring的基于注释的任务计划程序有问题-我无法使其正常运行,在这里我看不到任何问题...

I have a problem with Spring's annotation based task scheduler - I can't get it working, I don't see any problem here...

application-context.xml

application-context.xml

<task:scheduler id="taskScheduler" />
<task:executor id="taskExecutor" pool-size="1" />
<task:annotation-driven executor="taskExecutor" scheduler="taskScheduler" />

bean

@Service
public final class SchedulingTest {

    private static final Logger logger = Logger.getLogger(SchedulingTest.class);

    @Scheduled(fixedRate = 1000)
    public void test() {
        logger.debug(">>> Scheduled test service <<<");
    }

}

推荐答案

如果您想使用task:annotation-driven方法并且您的@Scheduled注释不起作用,那么您很可能在上下文xml中错过了context:component-scan. 没有这一行,spring无法猜测在哪里搜索注释.

If you want to use task:annotation-driven approach and your @Scheduled annotation is not working, then you most probably missed context:component-scan in your context xml. Without this line, spring cannot guess where to search for your annotations.

<context:component-scan base-package="..." />

这篇关于Spring Scheduler不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆