Xml代码 spring
<?xml version="1.0" encoding="UTF-8"?> spa
<beans xmlns="http://www.springframework.org/schema/beans" component
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xml
xmlns:context="http://www.springframework.org/schema/context" ci
xmlns:tx="http://www.springframework.org/schema/tx" it
xmlns:task="http://www.springframework.org/schema/task" io
xsi:schemaLocation=" table
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ast
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 配置
http://www.springframework.org/schema/context
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"
default-lazy-init="false">
<context:annotation-config />
<!―spring扫描注解的配置 -->
<context:component-scan base-package="com.gy.mytask" />
<!―开启这个配置,spring才能识别@Scheduled注解 -->
<task:annotation-driven scheduler="qbScheduler" mode="proxy"/>
<task:scheduler id="qbScheduler" pool-size="10"/>
字段 | 容许值 | 容许的特殊字符 |
秒 | 0-59 | , - * / |
分 | 0-59 | , - * / |
小时 | 0-23 | , - * / |
日期 | 1-31 | , - * ? / L W C |
月份 | 1-12 或者 JAN-DEC | , - * / |
星期 | 1-7 或者 SUN-SAT | , - * ? / L C # |
年(可选) | 留空, 1970-2099 | , - * / |
特殊字符 | 意义 |
* | 表示全部值; |
? | 表示未说明的值,即不关心它为什么值; |
- | 表示一个指定的范围; |
, | 表示附加一个可能值; |
/ | 符号前表示开始时间,符号后表示每次递增的值; |
L("last") | ("last") "L" 用在day-of-month字段意思是 "这个月最后一天";用在 day-of-week字段, 它简单意思是 "7" or "SAT"。若是在day-of-week字段里和数字联合使用,它的意思就是 "这个月的最后一个星期几" � 例如: "6L" means "这个月的最后一个星期五". 当咱们用“L”时,不指明一个列表值或者范围是很重要的,否则的话,咱们会获得一些意想不到的结果。 |
W("weekday") | 只能用在day-of-month字段。用来描叙最接近指定天的工做日(周一到周五)。例如:在day-of-month字 段用“15W”指“最接近这个月第15天的工做日”,即若是这个月第15天是周六,那么触发器将会在这个月第14天即周五触发;若是这个月第15天是周 日,那么触发器将会在这个月第16 天即周一触发;若是这个月第15天是周二,那么就在触发器这天触发。注意一点:这个用法只会在当前月计算值,不会越过当前月。“W”字符仅能在day- of-month指明一天,不能是一个范围或列表。也能够用“LW”来指定这个月的最后一个工做日。 |
# | 只能用在day-of-week字段。用来指定这个月的第几个周几。例:在day-of-week字段用"6#3"指这个月第3个周五(6指周五,3指第3个)。若是指定的日期不存在,触发器就不会触发。 |
C | 指和calendar联系后计算过的值。例:在day-of-month 字段用“5C”指在这个月第5天或以后包括calendar的第一天;在day-of-week字段用“1C”指在这周日或以后包括calendar的第一天。 |
在MONTH和Day Of Week字段里对字母大小写不敏感 。
"0 0 12 * * ?" | 天天中午12点触发 |
"0 15 10 ? * *" | 天天上午10:15触发 |
"0 15 10 * * ?" | 天天上午10:15触发 |
"0 15 10 * * ? *" | 天天上午10:15触发 |
"0 15 10 * * ? 2005" | 2005年的天天上午10:15触发 |
"0 * 14 * * ?" | 在天天下午2点到下午2:59期间的每1分钟触发 |
"0 0/5 14 * * ?" | 在天天下午2点到下午2:55期间的每5分钟触发 |
"0 0/5 14,18 * * ?" | 在天天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发 |
"0 0-5 14 * * ?" | 在天天下午2点到下午2:05期间的每1分钟触发 |
"0 10,44 14 ? 3 WED" | 每一年三月的星期三的下午2:10和2:44触发 |
"0 15 10 ? * MON-FRI" | 周一至周五的上午10:15触发 |
"0 15 10 15 * ?" | 每个月15日上午10:15触发 |
"0 15 10 L * ?" | 每个月最后一日的上午10:15触发 |
"0 15 10 ? * 6L" | 每个月的最后一个星期五上午10:15触发 |
"0 15 10 ? * 6L 2002-2005" | 2002年至2005年的每个月的最后一个星期五上午10:15触发 |
"0 15 10 ? * 6#3" | 每个月的第三个星期五上午10:15触发 |