spring自带task定时

xmlns 多加下面的内容、
  1. xmlns:task="http://www.springframework.org/schema/task"  
 
然后xsi:schemaLocation多加下面的内容、
  1. http://www.springframework.org/schema/task  
  2. http://www.springframework.org/schema/task/spring-task-3.1.xsd  
 
最后是我们的task任务扫描注解
  1. <task:annotation-driven/>  
 
我的配置扫描位置是:
  1. <context:annotation-config/>  
  2. <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>  
  3.     <context:component-scan base-package="com.test"/>  
 
扫描的是com.test这样的包下的内容、
下面需要接口和实现(我的这几个java文件都是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 * *  * * ? ")   //每5秒执行一次  
  4.       @Override  
  5.       public void myTest(){  
  6.             System.out.println("进入测试");  
  7.       }  

猜你喜欢

转载自www.cnblogs.com/kingdaqi/p/8974808.html
今日推荐