日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Schedule配置及初始化

發布時間:2024/4/13 javascript 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Schedule配置及初始化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
打開applicationContext,然后在現在的配置加一個標簽,takst:annotaion-driven,這里的driven有好幾個,我們選擇這一個<task:annotation-driven/>上面的xml的task已經加上了xmlns:task="http://www.springframework.org/schema/task"那剛剛選的時候一定不要選錯schema,雖然都是同一個annotaion-driven<context:property-placeholder location="classpath:datasource.properties"/>這個location我們怎么添加呢,首先我們先填上classpath,然后把這個配置閉合 <?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:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"xmlns:context="http://www.springframework.org/schema/context"xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"><context:component-scan base-package="com.learn" annotation-config="true"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /></context:component-scan><aop:aspectj-autoproxy/><!-- 二期新增spring schedule的時候新增的 --><context:property-placeholder location="classpath:datasource.properties"/><task:annotation-driven/><import resource="applicationContext-spring-session.xml"/><import resource="applicationContext-datasource.xml"/></beans> 首先我們創建一個類,這個類我們就叫CloseOrderTask,例如說下了一個訂單,30分鐘之類都沒有付款的話,那么我們就應該把這個訂單關閉,然后把這個下單的產品的庫存,再增加到產品表中,這樣就保證產品表的庫存又回來了,那既然我們要他把放到Spring容器當中,我們要加一個注解,@Component,然后使用@Slfj注解,來打印日志等,這樣我們對應Schedule的一個配置,就寫好了,然后我們在這里填充定時任務的方法,然后加上Schedule的注解呢,就可以啟動了,那既然我們要定時關單,注入Order相關的業務邏輯,那我們把OrderService注入進來,@Component @Slf4j public class CloseOrderTask {@Autowiredprivate IOrderService iOrderService;}

?

總結

以上是生活随笔為你收集整理的Spring Schedule配置及初始化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。