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

虾米哥 阅读:601 2021-03-31 21:52:06 评论:0

1、ssm框架基础jar 包

aopalliance.jar 
aspectjrt.jar 
aspectjweaver.jar 
commons-beanutils-1.9.2.jar 
commons-codec-1.9.jar 
commons-collections-3.2.1.jar 
commons-dbcp-1.4.jar 
commons-fileupload-1.3.1.jar 
commons-io-2.4.jar 
commons-lang-2.6.jar 
commons-logging-1.2.jar 
commons-net-3.1.jar 
commons-pool-1.6.jar 
commons-pool2-2.2.jar 
druid-1.0.9.jar 
fastjson-1.1.39.jar 
freemarker-2.3.19.jar 
hamcrest-core-1.3.jar 
jackson-all-1.9.5.jar 
jboss-logging-3.1.0.CR2.jar 
jettison-1.0.1.jar 
jstl-1.1.2.jar 
junit-4.11.jar 
log4j-1.2.17.jar 
log4j-over-slf4j-1.7.7.jar 
mybatis-3.2.6.jar 
mybatis-spring-1.2.2.jar 
mysql-connector-java-5.1.30-bin.jar 
servlet-api.jar 
slf4j-api-1.7.7.jar 
slf4j-ext-1.7.7.jar 
spring-aop-4.0.2.RELEASE.jar 
spring-aspects-4.0.2.RELEASE.jar 
spring-beans-4.0.2.RELEASE.jar 
spring-context-4.0.2.RELEASE.jar 
spring-context-support-4.0.2.RELEASE.jar 
spring-core-4.0.2.RELEASE.jar 
spring-expression-4.0.2.RELEASE.jar 
spring-jdbc-4.0.2.RELEASE.jar 
spring-oxm-4.0.2.RELEASE.jar 
spring-test-4.0.2.RELEASE.jar 
spring-tx-4.0.2.RELEASE.jar 
spring-web-4.0.4.RELEASE.jar 
spring-webmvc-4.0.2.RELEASE.jar 
standard-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服务器

标签:springMVC
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号