@Scheduled注解,定时任务

来源:互联网 发布:懂球帝软件 编辑:程序博客网 时间:2024/05/23 01:17
1、在spring配置文件中添加如下代码(命名空间)  xmlns:task="http://www.springframework.org/schema/task
   http://www.springframework.org/schema/task   http://www.springframework.org/schema/task/spring-task-3.1.xsd 

2、spring配置文件中配置定时任务
<!--定时任务--><task:annotation-driven/><context:annotation-config/><bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/><context:component-scan base-package="com.project.service"/>

3、在对应的包中添加定时任务(定时任务的表达式可以自己百度)
@Servicepublic class ScheduleService {    @Scheduled(cron = "0/5 * * * * ?")    public void scheduleTest(){        System.out.println("==========this is my schedual===========");    }}

0 0
原创粉丝点击