国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

java-spring mvc定時器(筆記)

2019-11-11 06:06:38
字體:
來源:轉載
供稿:網友

一個簡單的基于sPRing mvc的定時器

所需最少jar

web.xml配置:

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">    <!--Spring applicationContext 載入 -->    <listener>        <listener-class>            org.springframework.web.context.ContextLoaderListener        </listener-class>    </listener>        <!-- Spring ApplicationContext配置文件的路徑*,可使用通配符,多個路徑用*號分隔        此參數用于后面的Spring-Context loader -->    <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>classpath:com/timer/config/applicationContext.xml</param-value>    </context-param></web-app>

applicationContext.xml:

<?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:mvc="http://www.springframework.org/schema/mvc"    xmlns:task="http://www.springframework.org/schema/task"    xmlns:context="http://www.springframework.org/schema/context"     xsi:schemaLocation="       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd       http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"       default-autowire="byName" default-lazy-init="false">            <!-- 定時器開關-->    <task:annotation-driven />       <!-- 啟動Spring MVC的注解功能,完成請求和注解POJO的映射 -->    <mvc:annotation-driven />        <context:component-scan base-package="com.timer" /></beans>

定時器類:

package com.timer.controller;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Component;@Componentpublic class TimerController {        /**       * 每天凌晨清空所有用戶分享數據     */        @Scheduled(cron = "0 53 17 * * ?")       public void clearCustomerShare(){          System.out.println("========================sys");    }  }

//==========================cron表達式:http://rainbowdesert.iteye.com/blog/2107220

由6-7個組成

秒-分-時  天-月-日-年 用空格分開


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿城市| 沁水县| 政和县| 乌兰浩特市| 镇安县| 西盟| 凌云县| 台山市| 房产| 安丘市| 康马县| 东辽县| 禹州市| 贵溪市| 富顺县| 曲水县| 富民县| 嘉禾县| 濮阳县| 鹤壁市| 温宿县| 临高县| 依兰县| 克拉玛依市| 新晃| 西平县| 黔西县| 石楼县| 永春县| 垫江县| 灵山县| 沙湾县| 灵石县| 嘉义市| 桐庐县| 安国市| 东乡县| 湟源县| 清丰县| 全南县| 湖州市|