springboot實現動態定時任務

2021-10-18 22:15:28 字數 3291 閱讀 3198

* 定時任務工廠類

*/@component

public

class

jobfactory

extends

springbeanjobfactory

implements

@override

public

void

this

getautowirecapablebeanfactory()

;}}

public abstract class

abstracttask

implements

jobcatch

(exception e)

}public string getkey()

public

void

setkey

(string key)

public long getdatabaseid()

public

void

setdatabaseid

(long databaseid)

}

這裡可以寫你的業務**,實現具體的業務邏輯。

@component

("jobtask"

)public

class

jobtask

extends

abstracttask

}

包括專案啟動時新增定時任務,手動新增定時任務,更新定時任務,刪除定時任務方法。

/**

* 定時任務管理容器 component (單例模式)

*/@component

@scope

("singleton"

)public

class

jobquartzmanager

implements

catch

(schedulerexception e)

}public boolean addjob

(string jobname, long databaseid, class jobclass

, string cronexp)

)", cronexp)

;return result;

}try

catch

(exception e)

return result;

}public boolean updatejob

(string jobname, string cronexp)

)", cronexp)

;return result;

} jobkey jobkey =

newjobkey

(jobname,

job_group_name);

triggerkey triggerkey =

newtriggerkey

(jobname,

trigger_group_name);

tryelse

,group name:{} or trigger name:{},group name:{} not exists.."

, jobkey.

getname()

, jobkey.

getgroup()

, triggerkey.

getname()

, triggerkey.

getgroup()

);}}

catch

(schedulerexception e)

,group name:{} failed!"

, jobkey.

getname()

, jobkey.

getgroup()

);}return result;

}public boolean deletejob

(string jobname)

else

,group name:{} not exists."

, jobkey.

getname()

, jobkey.

getgroup()

);}}

catch

(schedulerexception e)

,group name:{} failed!"

, jobkey.

getname()

, jobkey.

getgroup()

);}return result;

} @override

public

void

this

}}

專案執行時給spring注入定時任務

/**

* 定時任務啟動類

*/@component

public

class

jobrunner

implements

}

@restcontroller

("/job"

)public

class

jobcontroller

else}(

"deletejob"

) @responsebody

public string deletejob

(@requestparam

("jobname"

) string jobname)

else}(

"updatejob"

) @responsebody

public string updatejob

(@requestparam

("jobname"

) string jobname, @requestparam

("cronexp"

) string cronexp)

else

}}

SpringBoot靜態動態

在src main resources下面有兩個資料夾,static和templates springboot預設 static中放靜態頁面,而templates中放動態頁面 靜態頁面 這裡我們直接在static放乙個hello.html,然後直接輸入http localhost 8080 hell...

django apscheduler實現定時任務

準備 1.安裝 pip install django apscheduler django apscheduler,3.註冊後資料遷移 python manage.py migrate 遷移之後會生成兩張表 django apscheduler djangojob django apschedule...

ASPxGridView子項動態邦定

一文,我有的地方說錯了,子項邦定資料,是完全可以動態的,昨天才研究出來,邦定資料方法 private void newmethod int i 得到點選行的主鍵,datatable data db.filldatatable pro string.format select from lsps bh...