使用@Scheduled注解编写spring定时任务

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * Created by chenguangjin on 2018/3/9.
 */
@Service
public class ScheduledTest {

    @Scheduled(cron = "0 0/1 * * * ?")
    public void scheduledMethod(){
        System.out.println("scheduled method start!");
    }

}

依赖:

    <properties>
        <spring.version>4.3.6.RELEASE</spring.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
    </dependencies>

 

posted @ 2018-03-09 15:04  C_Guangjin  阅读(160)  评论(0编辑  收藏  举报