SpringTask定时任务的配置和使用详解-创新互联

创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

延安ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!

记录下Spring自带的定时任务用法。

spring中使用定时任务

基于xml配置文件使用定时任务

首先配置spring开启定时任务

<beans xmlns="http://www.springframework.org/schema/beans" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  xmlns:p="http://www.springframework.org/schema/p" 
  xmlns:task="http://www.springframework.org/schema/task" 
  xmlns:context="http://www.springframework.org/schema/context" 
  xmlns:aop="http://www.springframework.org/schema/aop"  
  xsi:schemaLocation="http://www.springframework.org/schema/beans  
  http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd  
  http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
  http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"> 

  <task:annotation-driven /> <!-- 定时器开关--> 

  <bean id="myTask" class="com.spring.task.MyTask"></bean> 

  <task:scheduled-tasks> 
    <!-- 这里表示的是每隔五秒执行一次 --> 
    <task:scheduled ref="myTask" method="show" cron="*/5 * * * * ?" /> 
    <task:scheduled ref="myTask" method="print" cron="*/10 * * * * ?"/> 
  </task:scheduled-tasks> 

  <!-- 自动扫描的包名 -->
  <context:component-scan base-package="com.spring.task" /> 

</beans>

网站标题:SpringTask定时任务的配置和使用详解-创新互联
网页网址:https://www.cdcxhl.com/article2/ddodoc.html

成都网站建设公司_创新互联,为您提供网站排名网站制作动态网站手机网站建设搜索引擎优化外贸网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网页设计公司