用注解方式写定时任务

spring里加上 
</context:component-scan>
<!-- 任务自动扫描 -->
<task:annotation-driven/>
<!-- 扫描位置 -->
<context:annotation-config/>  
    <context:component-scan base-package="com.xxx.xxx"/>

然后在类上面添加注解  @Component,声明他是一个组件
原文地址:https://www.cnblogs.com/zhifengge/p/6180088.html