激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Java教程 - spring task 定時(shí)任務(wù)實(shí)現(xiàn)示例

spring task 定時(shí)任務(wù)實(shí)現(xiàn)示例

2020-07-28 14:45簡(jiǎn)單丶愛 Java教程

本篇文章主要介紹了spring task 定時(shí)任務(wù)實(shí)現(xiàn)示例,具有一定的參考價(jià)值,有興趣的可以了解一下。

一、引入spring相關(guān)jar包:

spring task 定時(shí)任務(wù)實(shí)現(xiàn)示例

二、在web.xml中配置spring

?
1
2
3
4
5
6
7
8
<listener>
  <description>Spring監(jiān)聽器</description>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
</context-param>

三、在applicationContext.xml中配置監(jiān)聽器

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  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.0.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-3.0.xsd
  http://www.springframework.org/schema/task
  http://www.springframework.org/schema/task/spring-task-3.0.xsd"
  default-lazy-init="false">
 
  <!-- 注解方式 -->
  <context:annotation-config />
  <context:component-scan base-package="com.test.task" />
  <task:annotation-driven/>
  
  <!-- XML方式 -->
  <!-- <bean name="testTask" class="com.test.task.TestTask" lazy-init="false"></bean>
  <task:scheduled-tasks> 
    <task:scheduled ref="testTask" method="print" cron="0/5 * * * * ?"/> 
  </task:scheduled-tasks> -->
 
</beans>

四、編寫實(shí)體類

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package com.test.task;
 
import java.text.DateFormat;
import java.util.Date;
 
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
@Component
public class TestTask {
  @Scheduled(cron = "*/5 * * * * ?")
  public void print(){
    String time = DateFormat.getDateTimeInstance().format(new Date());
    System.out.println("定時(shí)器觸發(fā)打印"+time);
  }
}

五、工程目錄:

spring task 定時(shí)任務(wù)實(shí)現(xiàn)示例

運(yùn)行結(jié)果:

spring task 定時(shí)任務(wù)實(shí)現(xiàn)示例

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 一级毛片免费高清视频 | 国产精品亚洲一区二区三区久久 | 黄色一级视频 | 久久男人视频 | 欧美zoofilia杂交videos | 日本看片一区二区三区高清 | 亚洲一区二区三区在线看 | 99r国产精品| 夏目友人帐第七季第一集 | 激情夜色 | 91精品国啪老师啪 | 国产成人在线一区 | 日韩一级免费毛片 | 欧美一区二区三区四区五区动图 | 一级国产航空美女毛片内谢 | 成人三级电影网 | 羞羞电影在线观看 | 国产精品一| 黄色高清免费网站 | 欧美亚洲另类在线 | 欧美一级淫片007 | 欧美一区二区黄色 | 斗破苍穹在线免费 | 成人在线观看免费爱爱 | 成人久久 | 成人免费电影av | 成年免费在线视频 | av在线一区二区三区 | 毛片视频免费观看 | 中文字幕11| 国产亚洲精品综合一区 | 爽毛片| 一区二区三区无码高清视频 | 久久精品日产第一区二区三区 | 国产免费v片| 91一区二区在线观看 | 久草高清视频 | 史上最强炼体老祖动漫在线观看 | h视频在线观看免费 | 黄色网址进入 | 国产精品久久99精品毛片三a |