下面的注解配置在ApplicationContext.xml文件中
<!-- 注解方式 -->
<context:annotation-config /><context:component-scan base-package="com.flf.task" />
<task:annotation-driven/>
此处为执行的任务方法
package com.flf.task;
import java.text.DateFormat;
import java.util.Date;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@PropertySource("classpath:base.properties")
public class Test {
@Scheduled(cron = "${task.cron}")
public void print() {
String time = DateFormat.getDateTimeInstance().format(new Date());
System.out.println("测试====定时器触发打印====" + time);
}
}
下面为base.properties 文件内容
task.cron=0 0/1 * * * ?