首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring集成quartz

2012-07-23 
spring集成quartz。spring的基础文件配置?1、applicationContext.xml??xml version1.0 encodingUTF-8

spring集成quartz。

spring的基础文件配置

?

1、applicationContext.xml

?

<?xml version="1.0" encoding="UTF-8" standalone="no"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   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/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"><!-- This will automatically locate any and all property files you have within your classpath, provided they fall under the META-INF/spring directory. The located property files are parsed and their values can then be used within application context files in the form of ${propertyKey}. --><context:property-placeholder location="classpath*:META-INF/spring/*.properties" /><context:spring-configured /><task:annotation-driven /><context:component-scan base-package="com.mogenesis"><context:exclude-filter expression="org.springframework.stereotype.Controller"type="annotation" /></context:component-scan><bean id="dataSource"><property name="driverClassName" value="${database.driverClassName}" /><property name="url" value="${database.url}" /><property name="username" value="${database.username}" /><property name="password" value="${database.password}" /></bean><bean ref="entityManagerFactory" /></bean><tx:annotation-driven transaction-manager="transactionManager" /><beanref="dataSource" /><property name="persistenceXmlLocation" value="classpath*:/META-INF/persistence-spring.xml" /><property name="loadTimeWeaver"><bean/></property></bean></beans>
?

?

?

2

编写job

package com.mogenesis.mobileadplatform.scheduling;import java.io.Serializable;import org.quartz.JobDataMap;import org.quartz.JobExecutionContext;import org.quartz.JobExecutionException;import org.quartz.StatefulJob;import org.springframework.scheduling.quartz.QuartzJobBean;/** * @author :xiaofancn * @version :2011-12-22 上午11:00:00 *  */public class ExampleJob extends QuartzJobBean implements StatefulJob,Serializable {private static final long serialVersionUID = 1L;@Overrideprotected void executeInternal(JobExecutionContext context)throws JobExecutionException {JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();System.out.println(ExampleJob.class);System.out.println("记忆时间" + jobDataMap.get("PreviousFireTime"));System.out.println("================================================");// 本次计划任务的开始结束时间System.out.println(context.getTrigger().getPreviousFireTime());// throw new JobExecutionException();System.out.println(context.getTrigger().getNextFireTime());// 上次任务的开始时间和本次任务的结束时间System.out.println(context.getPreviousFireTime());System.out.println(context.getNextFireTime());System.out.println("================================================");jobDataMap.put("PreviousFireTime", context.getNextFireTime());}}
?

?

?

?

?

?

3、quartz的属性配置文件?

quartz.properties

#default configorg.quartz.scheduler.instanceName = DefaultQuartzSchedulerorg.quartz.scheduler.rmi.export = falseorg.quartz.scheduler.rmi.proxy = falseorg.quartz.scheduler.wrapJobExecutionInUserTransaction = false#ThreadPool configorg.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPoolorg.quartz.threadPool.threadCount = 10org.quartz.threadPool.threadPriority = 5org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = trueorg.quartz.jobStore.misfireThreshold = 60000#jobStore RAM#org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore#jobStore Databaseorg.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTXorg.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegateorg.quartz.jobStore.tablePrefix = QRTZ_ org.quartz.jobStore.dataSource = qzDS 
?

?

4、quartz的配置文件

applicationContext-quartz.xml

?

<?xml version="1.0" encoding="UTF-8" standalone="no"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   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/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"><bean name="exampleJob" value="true" /><property name="jobClass"value="com.mogenesis.mobileadplatform.scheduling.ExampleJob" /><property name="jobDataAsMap"><map><entry key="timeout" value="5" /></map></property></bean><bean id="cronTrigger" ref="exampleJob" /><!-- run every morning at 6 AM --><property name="cronExpression" value="1/5 * * * * ?" /></bean><!-- 另一个事务管理器, Jdbc单数据源事务 --><bean id="quartzTransactionManager"ref="dataSource" /></bean><!-- Scheduler --><!-- <property name="waitForJobsToCompleteOnShutdown" value="true" /> 这个是可选,QuartzScheduler 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了 <property name="overwriteExistingJobs" value="true" /> <property name="transactionManager" ref="quartzTransactionManager" /> --><bean id="scheduler"ref="dataSource" /><property name="autoStartup" value="true" /><property name="waitForJobsToCompleteOnShutdown" value="true" /><property name="transactionManager" ref="quartzTransactionManager" /><property name="exposeSchedulerInRepository" value="true" /><!-- 这个是必须的,QuartzScheduler 延时启动,应用启动完后 QuartzScheduler 再启动 --><property name="startupDelay" value="10" /><property name="applicationContextSchedulerContextKey" value="applicationContext" /><property name="configLocation" value="classpath:META-INF/quartz/quartz.properties" /><property name="triggers"><list><ref bean="cronTrigger" /></list></property></bean></beans>
?

?

4、使用quartz提供的sql文件,初始化我们的PostgreSQL数据库

F:\quartz-1.8.5\quartz-1.8.5\docs\dbTables

热点排行