Quartz+spring instance Application

Source: Internet
Author: User

I life' s blog http://blog.csdn.net/fei1502816


1. JavaBean class
In the Test.quartzjob

Package Test;

           public class Quartzjob {public
              void work ()
              {
                    System.out.println () Quartz Task Scheduler ... ");
                 }
            }


2. Set the XML for spring
I created a new applicationcontext_quartz.xml, which reads as follows:

<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:jee= "Http://www.springframework.org/schema/jee" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-2.0.xsd Http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/ Spring-jee-2.0.xsd > <!--the work class to invoke--> <bean id= "Quartzjob" class= "Test.quartzjob" ></be An> <!--define methods for calling objects and calling objects--> <bean id= "Jobtask" class=
                Thodinvokingjobdetailfactorybean "> <!--called class--> <property name=" TargetObject "> <ref bean= "Quartzjob"/> </property> <!--calling methods in the class--> &L
 T;property name= "Targetmethod" > <value>work</value>           </property> </bean> <!--define trigger time--> <bean id= "Dotime" class= "Org.s" Pringframework.scheduling.quartz.CronTriggerBean "> <property name=" Jobdetail "> <re F bean= "Jobtask"/> </property> <!--cron expression--> <property name= "cron
            Expression "> <!--perform every 10 seconds--> &LT;VALUE&GT;0/10 * * * * * * *?</value> </property> </bean> <!--General Management class if the lazy-init= ' false ' then the container starts and executes the scheduler--> <bea n id= "Startquertz" lazy-init= "false" autowire= "no" class= "
                Org.springframework.scheduling.quartz.SchedulerFactoryBean "> <property name=" triggers "> 
        <list> <ref bean= "Dotime"/> </list> </property>
 </bean> </beans>

3. Set Web.xml to spring load

<!--load Spring-->
<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>
    /web-inf/classes/applicationcontext*.xml
   </param-value>
</ context-param>
<servlet>
   <servlet-name>context</servlet-name>
   < servlet-class>
    org.springframework.web.context.ContextLoaderServlet
   </servlet-class>
   <load-on-startup>1</load-on-startup>
</servlet>


Note: 1. import Quartz-all-1.5.2.jar Download http://download.csdn.net/source/1026766
2. Import Spring.jar (I used a spring2.0 previous version) Download http://download.csdn.net/source/1041819
If you don't import it,
Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean
Org.springframework.scheduling.quartz.CronTriggerBean
Org.springframework.scheduling.quartz.SchedulerFactoryBean
The three classes in spring can't be found, spring can't load properly, because the first time I use quartz, I just ignore this point, wasted a lot of time to tune configuration, in fact, there is no error in configuration.
3. You will ask why spring is not used
Quartz.properties
Quartz-jobsxml
Are these two files?
I replied: Yes, it will automatically find the default two files in the quartz package, and if you have special needs, you can define these two files yourself.

Attached: quartz.properties

# # Configure Main Scheduler Properties # org.quartz.scheduler.instanceName = Testscheduler Org.quartz.scheduler.instanc EId = one # # Configure ThreadPool # org.quartz.threadPool.class = Org.quartz.simpl.SimpleThreadPool Org.quartz.threadP Ool.threadcount = 5 org.quartz.threadPool.threadPriority = 4 # # Configure Jobstore # #org. quartz.jobStore.misfireThres Hold = 5000 #org. Quartz.jobStore.class = org.quartz.simpl.RAMJobStore # ============================================= ============================== # Configure Schedulerplugins =============================================== # = = ===================================================================== #org. Quartz.plugin.triggHistory.class = Org.quartz.plugins.history.LoggingTriggerHistoryPlugin #org. Quartz.plugin.triggHistory.triggerFiredMessage = Trigger {1}. {0} fired job {6}. {5} at: {4, date, HH:mm:ss mm/dd/yyyy} #org. quartz.plugin.triggHistory.triggerCompleteMessage = Trigger {1}. {0} completed firing job {6}. {5} at {4, DaTe, HH:mm:ss mm/dd/yyyy} with resulting trigger instruction code: {9} Org.quartz.plugin.jobInitializer.class = Org.quartz
. Plugins.xml.JobInitializationPlugin Org.quartz.plugin.jobInitializer.fileName =quartz_jobs.xml
Org.quartz.plugin.jobInitializer.overWriteExistingJobs = False Org.quartz.plugin.jobInitializer.failOnFileNotFound = True Org.quartz.plugin.shutdownhook.class = Org.quartz.plugins.management.ShutdownHookPlugin Org.quartz.plugin.shutdownhook.cleanShutdown = True


The system will find quartz_jobs.xml according to the configuration file

I reprint what not understand the place please visit

I life' s blog http://blog.csdn.net/fei1502816

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.