spring 使用注解啟動定時器不執行


spring 使用注解啟動定時器不執行

spring 配置: applicationContext.xml 

配置: 
Java代碼   收藏代碼
  1. <task:executor id="executor" pool-size="5" />    
  2.  <task:scheduler id="scheduler" pool-size="10" />    
  3.  <task:annotation-driven executor="executor" scheduler="scheduler" />   

命名空間: 
Java代碼   收藏代碼
  1. <beans xmlns="http://www.springframework.org/schema/beans"  
  2.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  3.        xmlns:context="http://www.springframework.org/schema/context"   
  4.        xmlns:tx="http://www.springframework.org/schema/tx"  
  5.        xmlns:security="http://www.springframework.org/schema/security"  
  6.        xmlns:amq="http://activemq.apache.org/schema/core"   
  7.        xmlns:jee="http://www.springframework.org/schema/jee"  
  8.        xmlns:task="http://www.springframework.org/schema/task"  
  9.        xsi:schemaLocation="  
  10. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  11. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
  12. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd   
  13. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
  14. http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd  
  15. http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd  
  16. http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd  
  17. http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd  
  18. " default-lazy-init="true">  



Java代碼   收藏代碼
  1. @Component  
  2. public class TestTask {  
  3.       
  4.     @Autowired  
  5.     private TestService testService;  
  6.       
  7.     @Scheduled(fixedDelay=5000)  
  8.     public void notifiy(){  
  9.         System.err.println("------------==========-------------");  
  10.           
  11.     }  
  12. }  


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com