您的位置:首页 > 编程语言 > Java开发

spring Quartz基于配置文件和注解的实现

2017-08-09 10:03 169 查看
这里只是做简单的记录如何实现。
一、基于配置文件的实现
①编写需要调度的类
注:里面的注解是后面的是注解的实现中用到的
②设置配置文件spring-quartz.xml
注意cron表达式,这里配置的是每隔1s执行。

③启动spring容器

二、基于注解的实现
①配置需要调度的类,并添加注解

②添加配置文件
<!--?xml version="1.0" encoding="UTF-8"?-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd  ">
<task:annotation-driven>
<context:component-scan base-package="com.study">
<context:annotation-config>
</context:annotation-config></context:component-scan></task:annotation-driven></beans>
③启动容器,这里通过配置web.xml启动
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息