當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring预处理
當需要在某些Spring項目一啟動,就執行某些操作時,需要實現改接口ApplicationListener,重寫onApplicationEvent方法,將需要的預處理操作全部寫在該方法中
當初始化完成WebApplicationContext后,spring容器一啟動,就將執行預處理操作。
@Service public class MyListener implements ApplicationListener<ContextRefreshedEvent>{Log logger = LogFactory.getLog(getClass());@Autowiredprivate OfficeToPdfManager officeToPdfManager;@Autowiredprivate OssService ossService;@Autowiredprivate NoteManager noteManager;@Overridepublic void onApplicationEvent(ContextRefreshedEvent event) {if(event.getApplicationContext().getParent() == null){new Thread(officeToPdfManager).start();logger.info("**線程以啟動");new Thread(ossService).start();logger.info("**線程以啟動");new Thread(noteManager).start();logger.info("**啟動");}}}如圖所示:
轉載于:https://www.cnblogs.com/leinuo2016/p/5241437.html
總結
- 上一篇: Eclipse中如何修改SVN的地址
- 下一篇: 8、JavaScript深入浅出——数据