JavaShuo
欄目
標籤
quartz結合spring例子
時間 2020-09-10
標籤
quartz
結合
spring
例子
欄目
Quartz
简体版
原文
原文鏈接
準備工做 下載quartz和spring相應的包
1.編寫測試類
public
class
SimpleService implements Serializable {
private
static
final
long
serialVersionUID = 122323233244334343L;
private
static
final Log logger = LogFactory.getLog(SimpleService.
class
);
public
void
testMethod1(){
//這裏執行定時調度業務 便於顯示明細添加些特殊符號
logger.info(
"testMethod1...@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@....1"
);
}
public
void
testMethod2(){
logger.info(
"testMethod2....###################################################!!!!!!!!!!!!!!!!!!!!...2"
);
}
}
2. 開始配置spring。
(1)配置spring的數據源
<bean id=
"dataSource"
class
=
"org.apache.commons.dbcp.BasicDataSource"
>
<property name=
"driverClassName"
>
<value>com.mysql.jdbc.Driver</value>
</property>
<property name=
"url"
>
<value>jdbc:mysql:
//127.0.0.1:3306/going</value>
</property>
<property name=
"username"
>
<value>root</value>
</property>
<property name=
"password"
>
<value>root</value>
</property>
<property name=
"maxActive"
>
<value>100</value>
</property>
<property name=
"maxIdle"
>
<value>2</value>
</property>
<property name=
"maxWait"
>
<value>1200</value>
</property>
</bean>
<!-- 下面是tomcat的 數據源 jndi的配置-->
<!--
<bean id=
"dataSource"
class
=
"org.springframework.jndi.JndiObjectFactoryBean"
abstract
=
"false"
>
<property name=
"jndiName"
>
<value>java:comp/env/jdbc/mysqlds</value>
</property>
</bean>
(2)配置spring和job的結合
<bean id=
"simpleService"
class
=
"com.going.oa.quartz.example5.SimpleService"
>
</bean>
<bean name=
"quartzScheduler"
class
=
"org.springframework.scheduling.quartz.SchedulerFactoryBean"
>
<property name=
"dataSource"
>
<
ref
bean=
"dataSource"
/>
</property>
<property name=
"applicationContextSchedulerContextKey"
value=
"applicationContextKey"
/>
<property name=
"configLocation"
value=
"classpath:quartz_priority.properties"
/>
<property name=
"triggers"
>
<list>
<
ref
bean=
"trigger1"
/>
<
ref
bean=
"trigger2"
/>
</list>
</property>
</bean>
<bean id=
"jobDetail1"
class
=
"frameworkx.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"
>
<property name=
"targetObject"
ref
=
"simpleService"
/>
<property name=
"targetMethod"
value=
"testMethod1"
/>
<property name=
"concurrent"
value=
"false"
/>
</bean>
<bean id=
"trigger1"
class
=
"org.springframework.scheduling.quartz.CronTriggerBean"
>
<property name=
"jobDetail"
ref
=
"jobDetail1"
/>
<property name=
"cronExpression"
value=
"0/5 * * ? * * *"
/>
</bean>
<bean id=
"jobDetail2"
class
=
"frameworkx.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"
>
<property name=
"targetObject"
ref
=
"simpleService"
/>
<property name=
"targetMethod"
value=
"testMethod2"
/>
<property name=
"concurrent"
value=
"false"
/>
</bean>
<bean id=
"trigger2"
class
=
"org.springframework.scheduling.quartz.SimpleTriggerBean"
>
<property name=
"jobDetail"
ref
=
"jobDetail2"
/>
<property name=
"startDelay"
value=
"1"
/>
<property name=
"repeatCount"
value=
"100"
/>
<property name=
"repeatInterval"
value=
"1000"
/>
</bean>
</beans>
注意上面frameworkx.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean類在spring的jar包中不提供,spring提供的MethodInvokingJobDetailFactoryBean有個bug因此須要到網上去下載這倆個文件
http://jira.springframework.org/browse/SPR-3797
3編寫測試類
package com.going.oa.quartz.example5;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Created by IntelliJ IDEA.
* User: weiyong
* Date: 2010-3-23
* Time: 13:57:51
* To change this template use File | Settings | File Templates.
*/
public
class
MainTest {
/**
* @param args
*/
public
static
void
main(String[] args) {
ApplicationContext springContext =
new
ClassPathXmlApplicationContext(
new
String[]{
"classpath:applicationContext-resources.xml"
,
"classpath:applicationContext-quartz.xml"
});
}
}
運行Ok
相關文章
1.
spring整合quartz
2.
Quartz使用例子
3.
spring boot整合Quartz
4.
spring boot 整合quartz
5.
spring boot整合JWT例子
6.
quartz框架使用 && Spring整合quartz
7.
Spring Quartz與Spring Task總結
8.
Quartz Spring與Spring Task總結
9.
quartz,spring-quartz,spring-task,spring-schedule
10.
【示例】Spring Quartz入門
更多相關文章...
•
MyBatis與Spring的整合實例
-
MyBatis教程
•
Spring體系結構詳解
-
Spring教程
•
Spring Cloud 微服務實戰(三) - 服務註冊與發現
•
算法總結-雙指針
相關標籤/搜索
結合案例
spring+quartz
quartz&spring
quartz+spring
quartz
例子
結合
tomcat+spring+quartz
spring+springmvc+mybatis+quartz
spring+websocket+quartz
Spring
Quartz
Spring教程
PHP 7 新特性
Redis教程
spring cloud
0
分享到微博
分享到微信
分享到QQ
每日一句
每一个你不满意的现在,都有一个你没有努力的曾经。
最新文章
1.
Appium入門
2.
Spring WebFlux 源碼分析(2)-Netty 服務器啓動服務流程 --TBD
3.
wxpython入門第六步(高級組件)
4.
CentOS7.5安裝SVN和可視化管理工具iF.SVNAdmin
5.
jedis 3.0.1中JedisPoolConfig對象缺少setMaxIdle、setMaxWaitMillis等方法,問題記錄
6.
一步一圖一代碼,一定要讓你真正徹底明白紅黑樹
7.
2018-04-12—(重點)源碼角度分析Handler運行原理
8.
Spring AOP源碼詳細解析
9.
Spring Cloud(1)
10.
python簡單爬去油價信息發送到公衆號
本站公眾號
歡迎關注本站公眾號,獲取更多信息
相關文章
1.
spring整合quartz
2.
Quartz使用例子
3.
spring boot整合Quartz
4.
spring boot 整合quartz
5.
spring boot整合JWT例子
6.
quartz框架使用 && Spring整合quartz
7.
Spring Quartz與Spring Task總結
8.
Quartz Spring與Spring Task總結
9.
quartz,spring-quartz,spring-task,spring-schedule
10.
【示例】Spring Quartz入門
>>更多相關文章<<