国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

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

服務器之家 - 編程語言 - Java教程 - spring task 定時任務實現示例

spring task 定時任務實現示例

2020-07-28 14:45簡單丶愛 Java教程

本篇文章主要介紹了spring task 定時任務實現示例,具有一定的參考價值,有興趣的可以了解一下。

一、引入spring相關jar包:

spring task 定時任務實現示例

二、在web.xml中配置spring

?
1
2
3
4
5
6
7
8
<listener>
  <description>Spring監聽器</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中配置監聽器

?
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>

四、編寫實體類

?
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("定時器觸發打印"+time);
  }
}

五、工程目錄:

spring task 定時任務實現示例

運行結果:

spring task 定時任務實現示例

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 精品三级三级三级三级三级 | 国产日韩欧美精品 | 国产精品免费一区二区三区四区 | 日韩在线综合 | 91亚洲国产成人久久精品网站 | 国产精品一区二区三区免费 | 久久久久久久久久久久久久av | 日韩精品视频在线 | 亚洲一区中文字幕 | 日韩精品在线免费观看 | 午夜免费在线 | 久久av网| 日本精品一区 | 69久久久| 亚洲天堂免费在线 | 久久精品免费观看 | 久久久久国产精品 | 成人a级片在线观看 | 欧美一级在线观看 | 欧美一级高清免费 | 国产成人一区二区三区 | 久草在线| 欧美日韩一区二区三区视频 | 日韩一区二区在线观看 | 欧美操穴 | 国产黄色在线播放 | 欧美精品理论片大全 | 日韩中文字幕在线视频 | 日韩在线小视频 | 亚洲电影在线播放 | 日韩在线一区二区三区 | 国产精品极品美女在线观看免费 | 国内外成人激情免费视频 | 午夜av网站 | 久久综合一区二区三区 | 一区二区三区在线播放 | 日日夜夜精品视频 | 日韩一二区 | 亚洲欧美精品 | 视频一区在线播放 | 亚洲精品免费在线观看 |