spring 使用注解启动定时器不执行

来源:互联网 发布:unity3d 掷骰子 编辑:程序博客网 时间:2024/06/05 19:25

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. }  

原创粉丝点击