Spring定时任务Job定时器

基于注解配置Spring定时任务
环境: Spring+SpringMVC+Hibernate

applicationContext.xml加上task注解扫描

开启下面配置,spring才能识别@Scheduled注解

<task:annotation-driven scheduler="qbScheduler" mode="proxy" />
<task:scheduler id="qbScheduler" pool-size="10" />

如果不能识别 task 标签 则需要在头部加入约束

http://www.springframework.org/schema/task 
http://www.springframework.org/schema/task/spring-task.xsd

准备任务完成

在需要的类方法上加入注解@Scheduled

@Component
public class MyJob {

    @Scheduled&#40;cron = "0/1 * * * * ?"&#41;
    public void execute  {
        System.out.println "Spring XML 配置 - MyJob";
    }
}

猜你喜欢

转载自blog.csdn.net/qq_37791322/article/details/81662245