使用过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文件配置:
创建测试类测试:
@Component
public class QuartzTest {
@Scheduled(fixedDelay = 1000)
public void test(){
System.out.println("定时任务开始执行");
}
}
将quartz配置文件加入到web.xml文件中:
contextConfigLocation
classpath:/spring-context.xml,classpath:/quartz-config.xml
本文介绍如何使用Spring框架结合Quartz实现基于注解的任务调度配置,简化了传统的XML配置方式,提高了开发效率。
1940

被折叠的 条评论
为什么被折叠?



