WEB-INF/ibm-web-bnd.xmi
<?xml version="1.0" encoding="UTF-8"?> <webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1237946146690" virtualHostName="default_host"> <webapp href="WEB-INF/web.xml#WebApp_1237946146690"/> <resRefBindings xmi:id="ResourceRefBinding_1238122581560" jndiName="wm/default"> <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1238122581560"/> </resRefBindings> </webappbnd:WebAppBinding>
web.xml
<resource-ref id="ResourceRef_1238122581560"> <res-ref-name>wm/default</res-ref-name> <res-type>commonj.work.WorkManager</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Unshareable</res-sharing-scope> </resource-ref>
注意:
<!-- 定义调度器 --> <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref local="myStatefulJobBean"/> </list> </property> <!--注入事务管理器--> <property name="transactionManager" ref="transactionManager"/> <!-- 引用配置文件 --> <property name="configLocation" value="classpath:conf/quartz.properties"/> <!-- 应用WorkManager --> <property name="taskExecutor" ref="taskExecutor"></property> </bean> <!-- 定义事务引用 --> <bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/> <!--配置使用IBM commonj WorkManager--> <bean id="taskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor"> <property name="workManagerName" value="wm/default"/> <property name="resourceRef" value="false"/> </bean> <!-- 声明有状态Job--> <bean id="myStatefulJobBean" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass" value="com.test.quartz.MyStatefulJobBean"/> </bean> <!-- 简单触发器 --> <bean id="hibernateTestTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> <property name="jobDetail" ref="myStatefulJobBean"/> <property name="startDelay"> <value>60000</value> </property> <property name="repeatInterval"> <value>60000</value> </property> </bean>
job bean
package com.test.quartz; import java.io.Serializable; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.quartz.SchedulerContext; import org.quartz.SchedulerException; import org.quartz.StatefulJob; import com.achievo.framework.workflow.HibernateSessionEnable; public class MyStatefulJobBean implements StatefulJob,Serializable{ @HibernateSessionEnable public void execute(JobExecutionContext context) throws JobExecutionException { String triggerName = context.getTrigger().getName(); String jobName = context.getJobDetail().getName(); System.out.println("触发器"+triggerName+"触发作业"+jobName); } }
配置JobStoreCMT 需要两个数据源: 容器管理的数据源 和 JDBC连接数据源
在quartz下载目录docs/dbTables 目录下有针对各种数据库的sql script文件
本文使用oracle,所以登录oracle sqlplus 执行 @quartz下载目录/docs/dbTables/tables_oracle.sql