ssm(spring+springMVC+Mybatis)框架 集成Quartz(定时任务框架)

来源:互联网 发布:caffe的test iter 编辑:程序博客网 时间:2024/05/30 22:59

1、ssm框架基础jar 包

aopalliance.jaraspectjrt.jaraspectjweaver.jarcommons-beanutils-1.9.2.jarcommons-codec-1.9.jarcommons-collections-3.2.1.jarcommons-dbcp-1.4.jarcommons-fileupload-1.3.1.jarcommons-io-2.4.jarcommons-lang-2.6.jarcommons-logging-1.2.jarcommons-net-3.1.jarcommons-pool-1.6.jarcommons-pool2-2.2.jardruid-1.0.9.jarfastjson-1.1.39.jarfreemarker-2.3.19.jarhamcrest-core-1.3.jarjackson-all-1.9.5.jarjboss-logging-3.1.0.CR2.jarjettison-1.0.1.jarjstl-1.1.2.jarjunit-4.11.jarlog4j-1.2.17.jarlog4j-over-slf4j-1.7.7.jarmybatis-3.2.6.jarmybatis-spring-1.2.2.jarmysql-connector-java-5.1.30-bin.jarservlet-api.jarslf4j-api-1.7.7.jarslf4j-ext-1.7.7.jarspring-aop-4.0.2.RELEASE.jarspring-aspects-4.0.2.RELEASE.jarspring-beans-4.0.2.RELEASE.jarspring-context-4.0.2.RELEASE.jarspring-context-support-4.0.2.RELEASE.jarspring-core-4.0.2.RELEASE.jarspring-expression-4.0.2.RELEASE.jarspring-jdbc-4.0.2.RELEASE.jarspring-oxm-4.0.2.RELEASE.jarspring-test-4.0.2.RELEASE.jarspring-tx-4.0.2.RELEASE.jarspring-web-4.0.4.RELEASE.jarspring-webmvc-4.0.2.RELEASE.jarstandard-1.1.2.jar

2、quartz 定时任务框架关联jar包

quartz-1.8.5.jar


3、quartz 定时任务实现类

package com.wlsq.oauth.quartz;import java.util.Date;public class SpringQtz {private static int counter = 0;protected void execute() {long ms = System.currentTimeMillis();System.out.println("\t\t" + new Date(ms));System.out.println("(" + counter++ + ")");}}

4、相关配置文件

<?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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans                          http://www.springframework.org/schema/beans/spring-beans-3.1.xsd                          http://www.springframework.org/schema/context                          http://www.springframework.org/schema/context/spring-context-3.1.xsd                          http://www.springframework.org/schema/tx                        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd                        http://www.springframework.org/schema/mvc                          http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd                        http://www.springframework.org/schema/aop                         http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"><!--运行时请将方式一注释掉! --><!-- 方式二:使用MethodInvokingJobDetailFactoryBean,任务类可以不实现Job接口,通过targetMethod指定调用方法 --><!-- 定义目标bean和bean中的方法 --><bean id="SpringQtzJob" class="com.wlsq.oauth.quartz.SpringQtz" /><bean id="SpringQtzJobMethod"class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"><property name="targetObject"><ref bean="SpringQtzJob" /></property><property name="targetMethod">  <!-- 要执行的方法名称 --><value>execute</value></property></bean><!-- ======================== 调度触发器 ======================== --><bean id="CronTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean"><property name="jobDetail" ref="SpringQtzJobMethod"></property><property name="cronExpression" value="*/5 * * * * ?"></property></bean><!-- ======================== 调度工厂 ======================== --><bean id="SpringJobSchedulerFactoryBean"class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="triggers"><list><ref bean="CronTriggerBean" /></list></property></bean></beans>

其他文件请查考:ssm框架集成memcached服务器

0 0
原创粉丝点击