Spring Schedule Timer Task (ii): How to configure a file

Source: Internet
Author: User

Next, you'll use the spring configuration file to generate spring timed tasks.
1, the corresponding web. XML does not change, so it is no longer listed. Similarly, the corresponding Java code business logic changes are not small, but on the original basis to remove@Component and @Scheduled (cron = "0/5 * * * *?") Parameters, that is, to turn this class and method into one of the simplest Java classes and methods.
2, since it is the way of configuration files, then the big change of nature is the Pring.xml configuration, the original annotated implementation of the timing function in the configuration, the changes after the configuration as follows:
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns:task= "Http://www.springframework.org/schema/task" xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns: context= "Http://www.springframework.org/schema/context" xsi:schemalocation= "http://www.springframework.org/ schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/ schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsdhttp:// Www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-3.1.xsd "> <!-- Specify the appropriate package--<context:component-scan base-package= "Scheduletest"/> <!--Specify the appropriate class--<bean id= "Sche Test1 "class=" Scheduletest.scheduletest1 "/> <!--specify Java classes and methods for the business logic to be executed by the scheduled task--<bean id=" scheTest11 "cl ass= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" > <property name= "TargetObject" > <ref local= "scheTest1"/> </property> <property name= "Targetmethod" > <!--the name of the method to be executed--<value>schTest1</value> </property> <pro Perty name= "Concurrent" value= "true"/> </bean> <!--define the trigger time--<bean id= "Schetest1cron" class = "Org.springframework.scheduling.quartz.CronTriggerBean" > <property name= "Jobdetail" > <ref bean= "scheTest11"/> </property> <property name= "Cronexpression" > <value> 0/5 * * * *?</value> </property> </bean> <!--trigger--<bean autowire= "No" cla ss= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" > <property name= "triggers" > &lt ;list> <ref local= "Schetest1cron"/> </list> </property> </bean></beans>

3, initially I did not import the other jar package, and then start the error classnotfound, as follows:
Org.springframework.beans.factory.CannotLoadBeanClassException:Cannot Find class [ Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean] for beans with the name ' scheTest11 ' defined in Class path resource [Spring1.xml]; Nested exception is java.lang.ClassNotFoundException: Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean

After checking the packet found that the package is not in the Spring-context.jar, but in the Spring-context-support.jar, so import this package. But then start to continue the error:
Java.lang.noclassdeffounderror:org/quartz/jobdetail

This is said to need to quartz this package, but did not import, so again import, start still error:
Java.lang.noclassdeffounderror:org/springframework/transaction/transactionexception

This mistake has seen, I know is less spring-tx.jar this package, so again import, start after finally see the results, five seconds to execute once. At this point, the implementation of the scheduled task is generated using the spring configuration file, and the MAVEN guide package is configured as follows:
<dependency> <groupId>org.springframework</groupId> <artifactid>spring-web</artif actid> <version>4.1.6.RELEASE</version> </dependency> <dependency> <grou Pid>org.springframework</groupid> <artifactId>spring-webmvc</artifactId> <version&gt ;4.1.6.release</version> </dependency> <dependency> <groupid>org.springframework</     Groupid> <artifactId>spring-context</artifactId> <version>4.1.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> &LT;ARTIFAC Tid>spring-context-support</artifactid> <version>4.0.9.RELEASE</version> </dependency&gt    ;        <dependency> <groupId>quartz</groupId> <artifactId>quartz</artifactId> <version>1.5.2</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>4.1.7.RELEASE</version> </dependenc Y> </dependencies>

Spring Schedule Timer Task (ii): How to configure Files

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.