Spring注解配置定时任务<task:annotation-driven/>
2017-04-12 16:00
561 查看
首先在配置文件头部的必须要有:
xmlns:task="http://www.springframework.org/schema/task"其次xsi:schemaLocation必须为其添加:
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd[/code]然后spring扫描过程必须涵盖定时任务类所在的目录:<context:component-scan base-package="com.xx.xx" />com.xx.xx属于定时任务类的父级甚至更高级
然后设置动作启用定时任务<task:annotation-driven/>
应用:
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@Lazy(value=false)
public class MyQuartzs {
@Scheduled(cron = "*/5 * * * * ?")//每隔5秒执行一次
public void test() throws Exception {
System.out.println("Test is working......");
}
//@Scheduled(cron = "0 0 1 * * ?")//每天凌晨1点整
//@Scheduled(cron = "0 30 0 * * ?")//每天凌晨0点30分
//@Scheduled(cron = "0 */60 * * * ?")//1小时处理一次
}
相关文章推荐
- Spring注解配置定时任务<task:annotation-driven/>
- Spring注解配置定时任务<task:annotation-driven/>
- Spring注解配置定时任务<task:annotation-driven/>
- Spring注解配置定时任务<task:annotation-driven/>
- Spring注解配置定时任务<task:annotation-driven/>
- spring注解配置<mvc:annotation-driven />与<context:annotation-config />区别
- spring使用<mvc:annotation-driven/>来解决定时任务
- spring <mvc:annotation-driven />注解意义
- spring mvc <mvc:annotation-driven>配置使用出现故障
- 使用@Controller注解为什么要配置<mvc:annotation-driven />
- 使用@Controller注解为什么要配置<mvc:annotation-driven />
- 使用@Controller注解为什么要配置<mvc:annotation-driven />
- Spring配置 <context:component-scan/> <mvc:annotation-driven />
- 使用@Controller注解为什么要配置<mvc:annotation-driven />
- 使用@Controller注解为什么要配置<mvc:annotation-driven />
- 在springmvc配置文件里面写默认的注解映射的支持的时候:<mvc:annotation-driven />The prefix "mvc" for element "mvc:annotation
- 160331、使用@Controller注解为什么要配置<mvc:annotation-driven />
- 使用@Controller注解为什么要配置<mvc:annotation-driven />
- 使用@Controller注解为什么要配置<mvc:annotation-driven />
- Spring配置文件详解:<context:annotation-config/>和<context:component-scan base-package=""/>和<mvc:annotation-driven />