spring 定时器配置

发布时间:2019-03-31 17:05:57

在spring.xml中的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.1.xsd


在文件中加入开启任务的配置

<task:annotation-driven/>



类文件代码

import java.text.SimpleDateFormat;

import java.util.Date;


import org.springframework.scheduling.annotation.Scheduled;

import org.springframework.stereotype.Component;


@Component  

public class TestJob {

    @Scheduled(fixedDelay = 5000) 

    public void test()

    {

        System.out.println("job 开始执行"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

    } 

}



Card image cap
APP STORE
Card image cap
应用宝
Card image cap
小米
Card image cap
华为