Spring統合Quartz
Spring統合Quartzの鍵はSpring xmlの構成にある
ApplicationContext.xml
5秒ごとにdoIt()メソッドを実行!
ApplicationContext.xml
- <?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:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xsi:schemaLocation="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/tx
- http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
-
-
-
- <!-- :java QuartzJobBean, -->
- <!-- JobDetail,java QuartzJobBean-->
- <bean name="exampleJob" class="org.springframework.scheduling.quartz.JobDetailBean">
- <property name="jobClass" value="com.yazuo.study.quartz.JobByQuartz" />
- <property name="jobDataAsMap">
- <map>
- <entry key="timeout" value="5" /><!-- -->
- </map>
- </property>
- </bean>
-
- <!-- simpleTrigger, , -->
- <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
- <property name="jobDetail" ref="exampleJob" /><!-- -->
- <property name="startDelay" value="1000" /><!-- -->
- <property name="repeatInterval" value="1000" /><!-- -->
- <property name="repeatCount" value="10" /><!-- -->
- </bean>
-
- <!-- : QuartzJobBean, java -->
- <!-- java -->
- <bean id="exampleBusinessObject" class="com.yazuo.study.quartz.JobOnly"/>
- <!--MethodInvokingJobDetailFactoryBean, quartz, java -->
- <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
- <property name="targetObject" ref="exampleBusinessObject" />
- <property name="targetMethod" value="doIt"/><!-- java -->
- <property name="concurrent" value="false" /><!-- -->
- </bean>
-
-
- <!-- CronTrigger: , <property name="cronExpression" value="0/1 2 13 * * ?" />-->
- <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
- <property name="jobDetail" ref="jobDetail" />
- <!--cron , readme.txt-->
- <property name="cronExpression" value="0/5 * * * * ?" />
- </bean>
-
- <!-- SchedulerFactory-->
- <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
- <property name="triggers">
- <list>
- <ref bean="cronTrigger" />
- <!--
- <ref bean="simpleTrigger"/>
- -->
- </list>
- </property>
- </bean>
- </beans>
- package com.yazuo.study.quartz;
-
- /**
- * org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean
- * QuartzJobBean, java , applicationContext.xml doIt()
- * doIt() ,
- *
- */
- public class JobOnly {
-
- public void doIt() {
- System.out.println("test MethodInvokingJobDetailFactoryBean");
- }
-
- }
5秒ごとにdoIt()メソッドを実行!