Spring定时任务注解

Spring3.0定时任务注解:

例:

//5秒钟执行一次

@Scheduled(fixedRate = 5000)
    public void reloadSEOCache() {
        logger.info("Reload SEO Cache");
    }

 

applicationContext.xml文件配置:

 

<beans default-autowire="no"
    xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:cache="http://www.springframework.org/schema/cache" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
           http://www.springframework.org/schema/task  
               http://www.springframework.org/schema/task/spring-task-3.0.xsd  
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

 

<!-- Spring Schedule Task -->
    <task:annotation-driven/>

</beans>

 

注:配置文件中需配置任务标签

http://www.springframework.org/schema/task  
http://www.springframework.org/schema/task/spring-task-3.0.xsd  

 

官方文档:

http://static.springsource.org/spring/docs/3.0.5.RELEASE/reference/scheduling.html

你可能感兴趣的:(spring)