• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
丶chunchun
博客园    首页    新随笔    联系   管理    订阅  订阅

spring定时任务

spring定时任务有两种实现方式:

1、注解方式

2、XML配置

 

在具体实现之前,我们需要在spring配置中引入一些东西:

xmlns 中的 xmlns:task="http://www.springframework.org/schema/task"

xsi 中的 http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">

引入job包:<context:component-scan base-package="job" /> 

具体配置如下:

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


<!-- 配置定时任务 -->
<!-- <task:scheduled-tasks>
<task:scheduled ref="TestScheduledJob" method="handleTask" cron="0/5 * * * * ?"/>
</task:scheduled-tasks> -->


<context:component-scan base-package="job" />

<task:annotation-driven/>
</beans>

 

1、注解方式(每五秒执行一次)

 

 

2、XML配置方式

 

 

posted @ 2018-08-30 22:25  丶chunchun  阅读(288)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3