Configuration problem: the 'initial-delay' attribute may not be used with cron and trigger tasks

使用spring定时任务配置如下:

<!-- 定时器开关 -->
    <task:annotation-driven />

    <!-- 定时执行规则 -->
    <task:scheduled-tasks>
        <task:scheduled ref="myTask" cron="*/10 * * * * ?" method="timeTask1" />
    </task:scheduled-tasks>

    <!-- 自动扫描的包名 -->
    <context:component-scan
        base-package="com.zc.www.task" />

这样的配置下,当我启动项目的过程中就会开始每十秒执行定时器.但是我想要他在项目启动后每十秒启动.于是我配置了这样:

<task:scheduled-tasks>
        <task:scheduled ref="myTask" initial-delay="10000" cron="*/10 * * * * ?" method="timeTask1" />
    </task:scheduled-tasks>

于是报错;查了下,这样设置延迟加载和cron这种冲突了,需要配置成固定的定时配置如下.

<!-- 定时执行规则 -->
    <task:scheduled-tasks>
        <task:scheduled ref="myTask" fixed-delay="10000" initial-delay="10000" method="timeTask1" />
    </task:scheduled-tasks>

这样配置后,就会在项目启动后每十秒执行.

猜你喜欢

转载自blog.csdn.net/myth_g/article/details/79711346