tomcat啟動(dòng)完成執(zhí)行 某個(gè)方法 定時(shí)任務(wù)(Spring)操作
第一步引入接口: ServletContextListener
@RestController@RequestMapping('/schedule')public class ScheduleController implements ServletContextListener { @Autowired private ScheduleService scheduleService; @Override public void contextDestroyed(ServletContextEvent event) { System.out.println('銷毀'); } @Override public void contextInitialized(ServletContextEvent event) { WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext()).getAutowireCapableBeanFactory().autowireBean(this); System.out.println('開始執(zhí)行周期任務(wù)'); scheduleService.start(); ; }}
如下圖:
第二步:在web.xml文件中配置監(jiān)聽
<listener> <listener-class>com.wbg.treasure.controller.ScheduleController</listener-class></listener>
以上這篇tomcat啟動(dòng)完成執(zhí)行 某個(gè)方法 定時(shí)任務(wù)(Spring)操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Python TestSuite生成測(cè)試報(bào)告過(guò)程解析2. 如何清空python的變量3. Vue作用域插槽實(shí)現(xiàn)方法及作用詳解4. 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法5. Python os庫(kù)常用操作代碼匯總6. Python 如何展開嵌套的序列7. IntelliJ IDEA設(shè)置默認(rèn)瀏覽器的方法8. 增大python字體的方法步驟9. Spring security 自定義過(guò)濾器實(shí)現(xiàn)Json參數(shù)傳遞并兼容表單參數(shù)(實(shí)例代碼)10. JAMon(Java Application Monitor)備忘記
