To add content to a scheduled task profile:
<beans xmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"xmlns:task= "Http://www.springframework.org/schema/task"xmlns:context= "Http://www.springframework.org/schema/context"xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://Www.springframework.org/schema/beans/spring-beans-3.0.xsd http://Www.springframework.org/schema/txHttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://Www.springframework.org/schema/jeeHttp://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://Www.springframework.org/schema/contextHttp://www.springframework.org/schema/context/spring-context-3.0.xsd http://Www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/ Spring-aop-3.0.xsd http://www.springframework.org/ Schema/task http://www.springframework.org/schema/ Task/spring-task-3.0.xsd" > <task:annotation-driven/> <!--timer Switch-- <bean id= "Mytaskxml" class= "com.spring.task.MyTaskXml" ></bean> <task :scheduled-tasks> <!-- This is what it means to do once every five seconds--<task:scheduled ref= "Mytaskxml" Method= "Show" cron= "*/5 * * * *?"/> <task:scheduled ref= "mytaskxml" method= "print" cron= "*/10 * * * * *?" /> </task:scheduled-tasks> <!--automatically scanned package name--<context:component-scan base- package= "Com.spring.task"/> </beans>
If the scheduled task is a profile:
Package Com.spring.task; /** @author*/Publicclass mytaskxml {public void Show () { System.out.println ("Xml:is show Run"); Public void print () { System.out.println ("xml:print run");} }
If it is an annotated scheduled task:
PackageCom.spring.task;Importorg.springframework.scheduling.annotation.Scheduled;Importorg.springframework.stereotype.Component;/*** Note-Based timers *@authorHJ*/@Component Public classmytaskannotation {/*** timed calculation. Once daily 01:00*/@Scheduled (Cron= "0 0 1 * * *") Public voidShow () {System.out.println ("Annotation:is Show Run"); } /*** Heartbeat update. Executes once at startup and then executes every 2 seconds*/@Scheduled (fixedrate= 1000*2) Public voidprint () {System.out.println ("Annotation:print Run"); }}
Test:
Package com.spring.test; Import Org.springframework.context.ApplicationContext; Import Org.springframework.context.support.ClassPathXmlApplicationContext; Public class Main { publicstaticvoid main (string[] args) { New Classpathxmlapplicationcontext ("Spring-mvc.xml");} }
Profiles and annotations for spring timed tasks