2. spring定时任务

1.添加命名空间

    <!-- 定时注解驱动 -->
    <task:annotation-driven />
    <!-- 进行定时任务的类,将其定义为一个bean -->
    <bean id="testJob" class="com.test.TestJob"></bean>
    <!-- 通过task标签,定义定时功能,每5秒执行一次 -->
    <task:scheduled-tasks>
        <task:scheduled ref="testJob" method="excute" cron="0/5 * * * * ?" />
    </task:scheduled-tasks>

定时任务类如下:

package com.test;
import org.springframework.stereotype.Component;

@Component
public class TestJob{ public void excute() { System.out.println("开始执行定时任务!"); } }

猜你喜欢

转载自www.cnblogs.com/zkx4213/p/10277182.html