Spring comes with task timing

xmlns add the following content,
  1. xmlns:task="http://www.springframework.org/schema/task"  
 
Then add the following to xsi:schemaLocation,
  1. http://www.springframework.org/schema/task  
  2. http://www.springframework.org/schema/task/spring-task-3.1.xsd  
 
Finally, our task task scan annotation
  1. <task:annotation-driven/>  
 
My config scan location is:
  1. <context:annotation-config/>  
  2. <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>  
  3.     <context:component-scan base-package="com.test"/>  
 
What is scanned is the content under packages such as com.test,
The interface and implementation are required below (my java files are all under the package of com.test)
  1. public interface IMyTestService {  
  2.        public void myTest();  
  3. }  
 
 
  1. @Component  //import org.springframework.stereotype.Component;  
  2. public class MyTestServiceImpl  implements IMyTestService {  
  3.       @Scheduled(cron="0/5 * * * * ? ") //Execute every 5 seconds  
  4.       @Override  
  5.       public void myTest(){  
  6.             System.out.println("进入测试");  
  7.       }  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325116079&siteId=291194637