您的位置:首页 > 编程语言 > Java开发

spring3.0定时器 xml配置和注解方式

2016-08-28 14:09 232 查看
1.xml配置方式

web.xml
[code=xml;toolbar:false"><!-- 配置spring监听器和配置文件路径 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>spring配置文件     
     <beans xmlns="http://www.springframework.org/schema/beans"
     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.0.xsd"
    
    <task:scheduled-tasks>   

        <task:scheduled ref="taskJob" method="job1" cron="0 * * * * ?"/>   

    </task:scheduled-tasks> 

    <context:component-scan base-package="com.gy.mytask" />这里定时每分钟的的零秒开始执行cron="0 * * * * ?"java类,方法无返回值package com.gy.mytask;

import org.springframework.stereotype.Service;

@Service

public class TaskJob {

    public void job1() {

        System.out.println("任务进行中。。。");
        System.out.println(Thread.currentThread().getName());

    }

}

[b]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: