Spring集成quartz
2015-08-22 11:54
537 查看
Quartz集成Spring基本使用(Web)
目录
1.所需jar.1
1)日志管理...1
2)spring核心包...1
3)quartz的spring支持...1
4)quartz及他的log支持...1
2.集成步骤...2
2.1开发一个业务job(POJ)2
2.2配置quartz(quartz.properties)2
2.3配置Spring下的quartz的任务(task.xml)2
2.4配置Spring(applicationContext.xml)2
2.5在web.xml中配置Spring(web.xml)2
3.基本使用源码...2
3.1开发一个业务job.2
3.2配置quartz.properties.3
3.3配置Spring下的任务task.xml4
3.4配置Spring,applicationContext.xml5
3.5在web.xml中配置Spring.5
log4j-1.2.16.jar
org.springframework.transaction-3.0.5.RELEASE.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
/**
* @authoryoupp
* job
*/
publicclassPrintReport {
/**
*
调度方法
*/
publicvoid run() {
System.out.println("打印报表");
}
}
#============================================================================
# Configure Main SchedulerProperties
#============================================================================
org.quartz.scheduler.instanceName =
EmailScheduler
org.quartz.scheduler.instanceId =
AUTO
#============================================================================
# Configure ThreadPool \u914D\u7F6E\u6570\u636E\u5E93\u8FDE\u63A5\u6C60
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount =
10
org.quartz.threadPool.threadPriority=
5
#============================================================================
# Configure JobStore \u914D\u7F6E\u505A\u4E1A\u5B58\u50A8\u65B9\u5F0F
#============================================================================
org.quartz.jobStore.class = org.quartz.impl.jdbcstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties =
false
#\u914D\u7F6EdataSource\u540D
org.quartz.jobStore.dataSource =
myDS
#\u8868\u524D\u7F00
org.quartz.jobStore.tablePrefix =
QRTZ_
org.quartz.jobStore.isClustered =
true
org.quartz.jobStore.clusterCheckinInterval=20000
#============================================================================
# Configure Datasources \u914D\u7F6E\u6570\u636E\u5E93\u7684\u8FDE\u63A5
#============================================================================
org.quartz.dataSource.myDS2.jndiURL=java\:comp/env/jdbc/insale
org.quartz.dataSource.myDS2.jndiAlwaysLookup=DB_JNDI_ALWAYS_LOOKUP
<!-- 配置在quartz中执行的调度任务 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd">
<!--定义业务处理对象 -->
<beanid="printReport"class="com.pan.quartz.job.PrintReport"/>
<!--定义调度业务逻辑 -->
<beanid="printReportjobDetail"class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!--调用的类 -->
<propertyname="targetObject"ref="printReport"/>
<!--调用的方法 -->
<propertyname="targetMethod"value="run"/>
<!--false表示等上一个任务执行完后再开启新的任务-->
<propertyname="concurrent"value="false"/>
</bean>
<!--定义调度触发器 -->
<beanid="printReportjobDetailcronTrigger"class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<propertyname="jobDetail"ref="printReportjobDetail"/>
<!--cron表达式 -->
<propertyname="cronExpression"value="0/10
* * * * ?"/><!--每10秒执行一次 -->
</bean>
<!--设置调度管理器 -->
<beanid="quartzM"lazy-init="false"autowire="no"class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<propertyname="triggers">
<list>
<ref bean="printReportjobDetailcronTrigger"/>
</list>
</property>
</bean>
</beans>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
">
<!--引入quartz任务配置 -->
<importresource="classpath:task.xml"/>
</beans>
<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="WebApp_ID"version="3.0">
<!-- Spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/applicationContext.xml</param-value>
</context-param>
<!-- Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
目录
1.所需jar.1
1)日志管理...1
2)spring核心包...1
3)quartz的spring支持...1
4)quartz及他的log支持...1
2.集成步骤...2
2.1开发一个业务job(POJ)2
2.2配置quartz(quartz.properties)2
2.3配置Spring下的quartz的任务(task.xml)2
2.4配置Spring(applicationContext.xml)2
2.5在web.xml中配置Spring(web.xml)2
3.基本使用源码...2
3.1开发一个业务job.2
3.2配置quartz.properties.3
3.3配置Spring下的任务task.xml4
3.4配置Spring,applicationContext.xml5
3.5在web.xml中配置Spring.5
1.所需jar
1)日志管理
commons-logging-1.1.1.jarlog4j-1.2.16.jar
2)spring核心包
3)quartz的spring支持
org.springframework.context.support-3.0.5.RELEASE.jarorg.springframework.transaction-3.0.5.RELEASE.jar
4)quartz及他的log支持
quartz-1.8.4.jarslf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
2.集成步骤
2.1开发一个业务job(POJ)
2.2配置quartz(quartz.properties)
2.3配置Spring下的quartz的任务(task.xml)
2.4配置Spring(applicationContext.xml)
2.5在web.xml中配置Spring(web.xml)
3.基本使用源码
3.1开发一个业务job
/**
* @authoryoupp
* job
*/
publicclassPrintReport {
/**
*
调度方法
*/
publicvoid run() {
System.out.println("打印报表");
}
}
3.2配置quartz.properties
#============================================================================
# Configure Main SchedulerProperties
#============================================================================
org.quartz.scheduler.instanceName =
EmailScheduler
org.quartz.scheduler.instanceId =
AUTO
#============================================================================
# Configure ThreadPool \u914D\u7F6E\u6570\u636E\u5E93\u8FDE\u63A5\u6C60
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount =
10
org.quartz.threadPool.threadPriority=
5
#============================================================================
# Configure JobStore \u914D\u7F6E\u505A\u4E1A\u5B58\u50A8\u65B9\u5F0F
#============================================================================
org.quartz.jobStore.class = org.quartz.impl.jdbcstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties =
false
#\u914D\u7F6EdataSource\u540D
org.quartz.jobStore.dataSource =
myDS
#\u8868\u524D\u7F00
org.quartz.jobStore.tablePrefix =
QRTZ_
org.quartz.jobStore.isClustered =
true
org.quartz.jobStore.clusterCheckinInterval=20000
#============================================================================
# Configure Datasources \u914D\u7F6E\u6570\u636E\u5E93\u7684\u8FDE\u63A5
#============================================================================
org.quartz.dataSource.myDS2.jndiURL=java\:comp/env/jdbc/insale
org.quartz.dataSource.myDS2.jndiAlwaysLookup=DB_JNDI_ALWAYS_LOOKUP
3.3配置Spring下的任务task.xml
<?xmlversion="1.0"encoding="UTF-8"?><!-- 配置在quartz中执行的调度任务 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd">
<!--定义业务处理对象 -->
<beanid="printReport"class="com.pan.quartz.job.PrintReport"/>
<!--定义调度业务逻辑 -->
<beanid="printReportjobDetail"class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!--调用的类 -->
<propertyname="targetObject"ref="printReport"/>
<!--调用的方法 -->
<propertyname="targetMethod"value="run"/>
<!--false表示等上一个任务执行完后再开启新的任务-->
<propertyname="concurrent"value="false"/>
</bean>
<!--定义调度触发器 -->
<beanid="printReportjobDetailcronTrigger"class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<propertyname="jobDetail"ref="printReportjobDetail"/>
<!--cron表达式 -->
<propertyname="cronExpression"value="0/10
* * * * ?"/><!--每10秒执行一次 -->
</bean>
<!--设置调度管理器 -->
<beanid="quartzM"lazy-init="false"autowire="no"class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<propertyname="triggers">
<list>
<ref bean="printReportjobDetailcronTrigger"/>
</list>
</property>
</bean>
</beans>
3.4配置Spring,applicationContext.xml
<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
">
<!--引入quartz任务配置 -->
<importresource="classpath:task.xml"/>
</beans>
3.5在web.xml中配置Spring
<?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="WebApp_ID"version="3.0">
<!-- Spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/applicationContext.xml</param-value>
</context-param>
<!-- Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
相关文章推荐
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- spring+html5实现安全传输随机数字密码键盘
- Spring中属性注入详解
- struts2 spring整合fieldError问题
- spring的jdbctemplate的crud的基类dao
- 读取spring配置文件的方法(spring读取资源文件)
- java实现简单美女拼图游戏
- java基本教程之线程休眠 java多线程教程
- JSP开发中在spring mvc项目中实现登录账号单浏览器登录
- PHP集成百度Ueditor 1.4.3
- ASP.NET中集成百度编辑器UEditor
- 基于Spring框架的Shiro配置方法
- Spring MVC中上传文件实例
- 实例讲解Java的Spring框架中的AOP实现
- 解析Java中如何获取Spring中配置的bean
- Spring的注解配置与XML配置之间的比较
- java Spring整合Freemarker的详细步骤
- Java 二维码,QR码,J4L-QRCode 的资料整理