創(chuàng)新互聯www.cdcxhl.cn八線動態(tài)BGP香港云服務器提供商,新人活動買多久送多久,劃算不套路!
記錄下Spring自帶的定時任務用法。
spring中使用定時任務
基于xml配置文件使用定時任務
首先配置spring開啟定時任務
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"> <task:annotation-driven /> <!-- 定時器開關--> <bean id="myTask" class="com.spring.task.MyTask"></bean> <task:scheduled-tasks> <!-- 這里表示的是每隔五秒執(zhí)行一次 --> <task:scheduled ref="myTask" method="show" cron="*/5 * * * * ?" /> <task:scheduled ref="myTask" method="print" cron="*/10 * * * * ?"/> </task:scheduled-tasks> <!-- 自動掃描的包名 --> <context:component-scan base-package="com.spring.task" /> </beans>
網站標題:SpringTask定時任務的配置和使用詳解-創(chuàng)新互聯
網頁網址:http://sd-ha.com/article2/ddodoc.html
成都網站建設公司_創(chuàng)新互聯,為您提供網站排名、網站制作、動態(tài)網站、手機網站建設、搜索引擎優(yōu)化、外貿網站建設
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯