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>