spring配置基于注解的quartz定时器

使用过spring整合的的quzrtz,虽然配置起来已经比较清晰容易,但还是避免不了有很多的xml文件中的配置,现在spring支持基于注解的quzrtz配置,可以很方便的使用,也免去了xml中冗余的配置。

增加quartz配置文件并建立命名空间:

xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation=http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-3.2.xsd

其他的按照需要增加。

XML文件配置:

<task:annotation-driven/>
	<context:annotation-config/>
	<context:component-scan base-package="com.lfex.quzrtz"/>
	<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

创建测试类测试:

@Component
public class QuartzTest {
	
	 @Scheduled(fixedDelay = 1000) 
	    public void test(){
	        System.out.println("定时任务开始执行");
	    } 
}

quartz配置文件加入到web.xml文件中:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:/spring-context.xml,classpath:/quartz-config.xml</param-value>
</context-param>


转载于:https://my.oschina.net/hanweifeng/blog/369186

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值