首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring定时器用Annotation兑现

2012-06-28 
spring定时器用Annotation实现?context:annotation-config /!--开启注解--?task:annotation-driven/

spring定时器用Annotation实现

?

<context:annotation-config /><!--开启注解-->?
<task:annotation-driven/> <!-- 这句是重点 定时器开?关-->

d)、web.xml
<listener>
? <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
< /listener>
?
?

2.完全注解方式

@Service
public class AnnotationQuartz {
? @Scheduled(cron="0,10,20,30,40,50 * * * * ?") //需要注意@Scheduled这个注解,它可配置多个属性:cron\fixedDelay\fixedRate
? public void test(){
? ? System.out.println("0.0");
? }
}

3.注解加配置方式

@Component(如果你的项目使用的是注解而不是配置文件中写bean,那么需要加上@Component,确保这个类已经注入)
public class AnnotationQuartz {
public void test()
{
System.out.println("0.0");
}
}

spring的ApplicationContext.xml中的配置:
<task:scheduled-tasks>?
<task:scheduled ref="chartsService" method="test" cron="0 0,15,30,45 * * * ?"/>?
< /task:scheduled-tasks>

4.相关文章

http://blog.springsource.com/2010/01/05/task-scheduling-simplifications-in-spring-3-0/

http://jooben.blog.51cto.com/253727/406277?

?

5.实际使用情况

按如上配置之后,定时器根本就没反应,不知道哪里的问题,还是用老方法,配置方式吧

<bean id="smsSenderTimerQuarz" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="quartzSMSSender"/>
</property>
<property name="cronExpression">
<value>0 0/5 * * * ?</value>?
</property>
</bea?n>

热点排行