以下是本人另外一種實現方式,跟@Scheduled註解配置有點不一樣
1.在xml里加入task的命名空間
xmlns:task="http://www.springframework.org/schema/task"
2.在
xsi:schemaLocation加http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.3.xsd
3.定時器設置
<bean name="testTask" class="sy.scheduler.MediaTask" lazy-init="false"></bean>
<task:scheduled-tasks>
<task:scheduled ref="testTask" method="TaskJob" cron="0/2 * * * * ?"/>
</task:scheduled-tasks>
4.後臺定時器代碼
package sy.scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import sy.service.AppBusinessServiceI;
public class MediaTask {
public void TaskJob() {
System.out.println("this is timer job...");
}
}