spring 注解方式配置定时任务
2016-08-08 13:53
393 查看
一、注解的方式
1:spring 配置文件中增加这句
2:确保扫描程序能够扫描后 下面第3步骤的java类
3:AnnotationQuartz.java
二、不需要配置文件,只要加扫描就好
1:确保扫描程序能够扫描后 下面第3步骤的java类
2:AnnotationQuartz.java
第三种用@EnableScheduling完美代替了配置。
1:spring 配置文件中增加这句
<task:annotation-driven/>
2:确保扫描程序能够扫描后 下面第3步骤的java类
<context:component-scan base-package="cms"/>
3:AnnotationQuartz.java
package cms; import base.util.BaseDateUtil; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.Date; @Component public class AnnotationQuartz { @Scheduled(cron = "0 0/1 15,* * * ?") //需要注意@Scheduled这个注解,它可配置多个属性:cron\fixedDelay\fixedRate public void test() { String dateStr = BaseDateUtil.getFormatString(new Date(), "yyyy-MM-dd HH:mm:ss"); System.out.println("小说城 www.xiaoshuocity.com 每分钟执行一次:" + dateStr); } }
二、不需要配置文件,只要加扫描就好
1:确保扫描程序能够扫描后 下面第3步骤的java类
<context:component-scan base-package="cms"/>
2:AnnotationQuartz.java
package cms; import base.util.BaseDateUtil; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.Date; @EnableScheduling @Component @Lazy(false) public class AnnotationQuartz { @Scheduled(cron = "0 0/1 15,* * * ?") //需要注意@Scheduled这个注解,它可配置多个属性:cron\fixedDelay\fixedRate public void test() { String dateStr = BaseDateUtil.getFormatString(new Date(), "yyyy-MM-dd HH:mm:ss"); System.out.println("小说城 www.xiaoshuocity.com 每分钟执行一次:" + dateStr); } }
第三种用@EnableScheduling完美代替了配置。
相关文章推荐
- spring纯注解方式简单配置定时任务
- spring 注解方式配置定时任务
- java spring注解方式配置定时任务
- spring的注解方式执行定时任务
- spring的两种定时任务配置方式
- spring自带的定时任务功能,基于注解和xml配置
- Spring3.X 配置(注解)定时任务
- Spring注解配置定时任务<task:annotation-driven/>
- 使用spring@Schedule注解定时任务时将时间表达式写入配置文件中的方法
- spring自带的定时任务功能,基于注解和xml配置(转载)
- Spring注解形式的定时任务配置详解(转)
- spring自带的定时任务功能,基于注解和xml配置
- spring task 定时任务 注解方式 demo
- spring定时任务注解形式主要的配置步骤
- spring和quartz整合实现定时任务(配置文件配置方式
- 使用Spring定时器定时任务的几种配置方式及示例
- spring quartz 注解配置定时任务
- Spring注解配置定时任务<task:annotation-driven/>
- spring中通过配置文件方式实现定时任务
- Spring注解配置定时任务<task:annotation-driven/>