zoukankan      html  css  js  c++  java
  • spring @Scheduled注解 定时任务 详解

    scheduled的使用注解的方式进行调度

    先要配置spring.xml

    xmlns:task="http://www.springframework.org/schema/task"  

    然后xsi:schemaLocation

    http://www.springframework.org/schema/task  
    http://www.springframework.org/schema/task/spring-task-3.1.xsd 

    再加上扫描注解

    <task:annotation-driven/>  

    然后扫描位置

    <context:annotation-config/>  
        <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>  
        <context:component-scan base-package="com.zyt.test"/>  

    调用

    import org.springframework.stereotype.Component;  
    
    @Component  
    public class TestService {  
        // 5秒钟执行一次 @Scheduled(cron
    ="0/5 * * * * ? ") //每5秒执行一次
        public void test(){ System.out.println("每隔五秒打印一次"); } }

    @Scheduled 注解要写在实现方法上

    定时器的任务方法不能有返回值(如果有返回值的话,spring初始化的时候会报错,需要设定一个proxytargetclass的某个值为true,请自行百度google)

    剩下的就是corn表达式了

    请自行百度google

  • 相关阅读:
    MOSS工作流开发+ Email提醒
    使用VS.net開發MOSS工作流(請假單)
    配置单一登录
    使用VS.NET手動創建一個MOSS的BDC實體
    UDDI&wsdl
    telnet
    thoughtworks~
    GIS
    MySQL中修改root密码的方法[转]
    libconfig
  • 原文地址:https://www.cnblogs.com/zhouyantong/p/6904177.html
Copyright © 2011-2022 走看看