欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2017年01月19日 10:14:16   作者:簡單丶愛  
本篇文章主要介紹了spring task 定時(shí)任務(wù)實(shí)現(xiàn)示例,具有一定的參考價(jià)值,有興趣的可以了解一下。

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

二、在web.xml中配置spring

<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)聽器

<?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í)體類

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);
  }
}

五、工程目錄:

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot靜態(tài)資源的訪問方法詳細(xì)介紹

    SpringBoot靜態(tài)資源的訪問方法詳細(xì)介紹

    最近在做SpringBoot項(xiàng)目的時(shí)候遇到了“白頁”問題,通過查資料對SpringBoot訪問靜態(tài)資源做了總結(jié),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2022-09-09
  • SpringCloud搭建Eureka服務(wù)模塊的過程

    SpringCloud搭建Eureka服務(wù)模塊的過程

    Eureka在分布式系統(tǒng)中起到了連接各個微服務(wù)的紐帶作用,使得服務(wù)之間的交互變得更加靈活、可靠,本文將深入探討如何使用Spring?Cloud,逐步引導(dǎo)讀者完成Eureka服務(wù)模塊的搭建,感興趣的朋友跟隨小編一起看看吧
    2024-02-02
  • Spring-data-redis操作redis知識總結(jié)

    Spring-data-redis操作redis知識總結(jié)

    這篇文章主要介紹了Spring-data-redis操作redis知識總結(jié),spring-data-redis是spring-data模塊的一部分,專門用來支持在spring管理項(xiàng)目對redis的操作。
    2017-04-04
  • springboot 設(shè)置server.port不生效的原因及解決

    springboot 設(shè)置server.port不生效的原因及解決

    這篇文章主要介紹了springboot 設(shè)置server.port不生效的原因及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • 記錄jdk21連接SQLServer因?yàn)門LS協(xié)議報(bào)錯問題

    記錄jdk21連接SQLServer因?yàn)門LS協(xié)議報(bào)錯問題

    在使用Druid連接池連接SQL Server時(shí),可能會遇到因TLS版本不匹配導(dǎo)致的連接失敗問題,具體表現(xiàn)為客戶端使用TLS1.3或TLS1.2,而SQL Server僅支持TLS1.0,導(dǎo)致無法建立安全連接,解決方法是修改JDK的安全配置,啟用TLS1.0
    2024-10-10
  • Java實(shí)現(xiàn)讀取Jar文件屬性的方法詳解

    Java實(shí)現(xiàn)讀取Jar文件屬性的方法詳解

    這篇文章主要為大家詳細(xì)介紹了如何利用Java語言實(shí)現(xiàn)讀取Jar文件屬性的功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2022-08-08
  • 使用spring?data的page和pageable如何實(shí)現(xiàn)分頁查詢

    使用spring?data的page和pageable如何實(shí)現(xiàn)分頁查詢

    這篇文章主要介紹了使用spring?data的page和pageable如何實(shí)現(xiàn)分頁查詢,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • Mybatis執(zhí)行多條語句/批量更新方式

    Mybatis執(zhí)行多條語句/批量更新方式

    這篇文章主要介紹了Mybatis執(zhí)行多條語句/批量更新方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Java lambda表達(dá)式實(shí)現(xiàn)Flink WordCount過程解析

    Java lambda表達(dá)式實(shí)現(xiàn)Flink WordCount過程解析

    這篇文章主要介紹了Java lambda表達(dá)式實(shí)現(xiàn)Flink WordCount過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • Java中的@PostConstruct注解用法詳解

    Java中的@PostConstruct注解用法詳解

    @PostConstruct注解是Java中一個強(qiáng)大的特性,它允許開發(fā)人員在Bean被構(gòu)造并且依賴被注入后執(zhí)行初始化邏輯,本文將從源碼和用法的角度深入解析@PostConstruct注解,探討其實(shí)現(xiàn)細(xì)節(jié)和實(shí)際應(yīng)用
    2023-07-07

最新評論