自己用spring3.2+quartz+maven 整合一个小小的demo.仅供自己学习!
1. 在HelloController 中注入 IPersionService 接口,并调用PersionService 的save() 方法。
2. 在 application-context-quartz 中配置quartz 和Spring。
3. 在web.xml配置监听和application-context-quatz.xml
4:具体如下
/** * @author * @date 创建时间:2016-1-5 上午10:01:26 * @version 1.0 */ @Controller @RequestMapping(value = "/hello") public class HelloController { @Autowired private IPersionService iPersionService; SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); @RequestMapping(value = "/say", method = RequestMethod.GET) public void show(){ iPersionService.save(); } }
/** * @author * @date 创建时间:2016-1-5 下午2:39:51 * @version 1.0 */ @Service public class PersionService implements IPersionService { SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); public void save() { System.out.println("save:"+dateFormat.format(new Date())); System.err.println("invok persionService save method !"); } }
/** * @author * @date 创建时间:2016-1-5 下午2:37:43 * @version 1.0 */ public interface IPersionService { public void save(); }
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:cache="http://www.springframework.org/schema/cache" 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/aop http://www.springframework.org/schema/aop/spring-aop-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/cache http://www.springframework.org/schema/cache/spring-cache-3.0.xsd"> <context:component-scan base-package="com.sys"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" /> </context:component-scan> <!-- 自定义需要执行定时任务的类 --> <bean id="quartzJob" class="com.sys.service.PersionService" /> <!-- 定义调用对象和调用对象的方法 --> <bean id="jobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 调用的类 --> <property name="targetObject"> <ref bean="quartzJob" /> </property> <property name="targetMethod"> <value>save</value> </property> </bean> <!-- 定义触发时间 --> <bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail"> <ref bean="jobTask" /> </property> <property name="cronExpression"> <value>0/30 * * * * ?</value> <!-- <value>0 0/5 * * * ?</value> --> </property> </bean>
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- Spring config start --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:/application-context-quartz.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- Spring config end --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 --> <bean id="startQuartz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="doTime" /> </list> </property> </bean> </beans>
相关推荐
Spring Boot+Apache Shiro+Spring MVC+MyBatis+Quartz+Druid DEMO
本代码是定时器的实例,两种运行模式,一种是直接以Java程序的形式运行,指定加载的配置文件;另一种是在tomcat下运行
spring+springMVC+mybatis+quartz动态定时任务
spring4+hibernate5+quartz2+hdfs.rar,开箱即用,里面已经提供了实现了,只需要提交自己的jdbc连接
整合Spring3.0+quartz-2.1.6 ..............................................................................
史上最全mybatis + spring + springmvc + maven + json + quartz整合jar包,需要的拿走!
Spring4.3.15 + Quartz2.2 + Spring MVC管理可以管理任务的暂停,启动、立即执行一次、根据表达式重新调度等功能
里面包含了两个工程项目: 1.Java project工程(含jar包,JDK1.6)。 是spring+quartz的任务调度实例。 2.Java web工程(含jar包,JDK1.7)。 spring+mybatis+quartz任务调度实例
shiro+SpringMVC+Spring+mybatis+maven+mybatis 自动刷新+ Quartz scheduler 定时器管理
利用quartz动态操作定时任务,所有配置信息扔到数据库合理管理,同时把运行日志自动添加数据库表中。
spring 3.2.2 + quartz 2.1 需要的包 包括 quartz-2.1.5.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.1.jar spring-context-support-3.2.0.RELEASE.jar
spring3+quartz1.6.4 集群示例源代码
● 实现方法: 使用MySQL 建立数据库。服务端使用SSM框架(Spring+SpringMVC+MyBatis)+shiro+Maven,使用Myeclipse进行开发。前端使用MUi和HUI框架和vue(与后台交互模板)和Html5+css3来实现移动端App的开发。
spring3.0+quartz-1.6.0实现定时任务
基于spring-boot+quartz的CRUD任务管理系统源码+项目说明.zip基于spring-boot+quartz的CRUD任务管理系统源码+项目说明.zip基于spring-boot+quartz的CRUD任务管理系统源码+项目说明.zip基于spring-boot+quartz的CRUD...
以SpringBoot 为中心,模块化开发系统,用户可以随意删减除权限...复用,组装性强主要应用技术:spring Security+Ehcache+quartz+swagger2+Mysql5.6+springjdbc+druid+spring social+spring session + layerui+vue.js
Spring3.2.4 + Quartz2.2.0集成实例 可参考http://blog.csdn.net/liangbinny/article/details/17284691
spring+quartz定时小例子,架包+文档 我自己整理的
spring4.0.6+quartz 2.2.3 集群示例