Integrate quartz with spring (online example + self-configuration)

Source: Internet
Author: User

I use myeclipse6.0 spring 2.0 and quartz 1.5.2;

Main steps:

Create a web project:

First import jar package: quartz-1.5.2.jar, spring. Jar (these two are enough );

Then configure web. xml:

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><servlet><servlet-name>spring</servlet-name><servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>spring</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>

Configure the spring configuration file 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" xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id = "firstjob" class = "com. MC. job. first "> </bean> <! -- Define methods in the target bean and bean --> <bean id = "job" class = "org. springframework. scheduling. quartz. methodinvokingjobdetailfactorybean "> <property name =" targetobject "> <ref local =" firstjob "/> </property> <property name =" targetmethod "> <! -- Name of the method to be executed --> <value> count </value> </property> </bean> <! -- Define the trigger time --> <bean id = "cron" class = "org. springframework. scheduling. quartz. crontriggerbean "> <property name =" jobdetail "> <ref bean =" job "/> </property> <property name =" cronexpression "> <value> 0-59 ** **? </Value> </property> </bean> <! -- Manage triggers --> <bean autowire = "no" class = "org. springframework. scheduling. quartz. schedulerfactorybean "> <property name =" triggers "> <list> <ref local =" cron "/> </List> </property> </bean> </beans>

The last is the test class: first. Java

package com.mc.job;public class First {static long Count = 0;public void Count() {Count++;System.out.print("Count1="+Count);}}

A simple example of configuration integration is completed...
The source code package of the entire demo (including the required jar package) can be downloaded to my resources: http://download.csdn.net/detail/jerry_bj/3618605

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.