Spring之——quartz使用@Scheduled注解执行定时任务

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/52865052

今天,给大家来一篇Spring的小插曲,用@Scheduled注解来实现Spring quartz的定时执行任务功能。

导入Spring与Spring quartz相关的jar包,配置applicationContext.xml文件

xmlns 多加下面的内容

xmlns:task="http://www.springframework.org/schema/task"
然后xsi:schemaLocation多加下面的内容
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd
最后是我们的task任务扫描注解
<task:annotation-driven/>
我的配置扫描位置是

<context:annotation-config/>
    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
    <context:component-scan base-package="com.test"/>
扫描的是com.test这样的包下的内容、

下面需要接口和实现(我的这几个Java文件都是com.test的包下的、)

public interface IMyTestService {
       public void myTest();
}
@Component  //import org.springframework.stereotype.Component;
public class MyTestServiceImpl  implements IMyTestService {
      @Scheduled(cron="0/5 * *  * * ? ")   //每5秒执行一次
      @Override
      public void myTest(){
            System.out.println("进入测试");
      }
}
这样就配置好了,然后我们就可以测试定时任务了。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰 河

可以吃鸡腿么?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值