當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring Schedule配置及初始化
生活随笔
收集整理的這篇文章主要介紹了
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配置及初始化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring Schedule定时关单快
- 下一篇: Spring Schedule关闭订单