Schedule exists in the Spring-context.jar package.
To implement a simple step:
1. Configure Bean.xml to turn on timed task support.
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"Xmlns:task= "Http://www.springframework.org/schema/task"xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans /spring-beans.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-context.xsd HTTP://WWW.SPRINGFRAMEWORK.O Rg/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd Http://www.springframework.org/schema/task http://www.springframework.org/schema/task/s Pring-task.xsd "> <!--turn on timed tasks--<task:annotation-driven/> <Context:component-scanBase-package= "Com.jsoft.testspring" /> <Context:annotation-config/> <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "prefix"> <value>/web-inf/jsp/</value> </ Property> < Propertyname= "suffix"> <value>. jsp</value> </ Property> </Bean> </Beans>
Code implementation:
PackageCom.jsoft.testspring.testmvchelloworld;ImportJava.text.SimpleDateFormat;Importjava.util.Date;Importorg.springframework.scheduling.annotation.Scheduled;Importorg.springframework.stereotype.Component; @Component Public classscheduletest { @Scheduled (cron = "0/5 * * * *?" ) Public voidSchTest1 () {Date Date=NewDate (); SimpleDateFormat Sim=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); String Datestr=Sim.format (date); System.out.println ("This is spring timer 1, executed every five seconds, current time:" +datestr); } }
Note that annotations such as @component are added.
Example Project: Https://github.com/easonjim/5_java_example/tree/master/springtest/test24/testmvchelloworld
Reference:
http://blog.csdn.net/tuzongxun/article/details/51576301
Spring MVC uses schedule to implement timed tasks