ycs計算框架流程
阿新 • • 發佈:2018-12-19
看程式碼前要先了解這些知識:
Servlet ServletContextEvent事件
下面是JS框架實現程式碼:
public class RuleEngineListener implements ServletContextListener { private static Logger logger = Logger.getLogger(RuleEngineListener.class); /** * 當Servlet 容器終止Web 應用時呼叫該方法。在呼叫該方法之前,容器會先銷燬所有的Servlet 和Filter 過濾器。 */ public void contextDestroyed(ServletContextEvent arg0) { } /** * 容器初始化時啟動一個新執行緒載入所有的業務規則並生成JS檔案. */ public void contextInitialized(ServletContextEvent arg0) { if (logger.isDebugEnabled()) { logger.debug("RuleEngineListener context Initialize start."); } WebApplicationContext rwp = WebApplicationContextUtils .getRequiredWebApplicationContext(arg0.getServletContext()); ILoadRuleService loadRuleService = (ILoadRuleService) rwp .getBean("nssb_gzyq_loadRuleService"); ICreateJsFileService createJsFileService = (ICreateJsFileService) rwp .getBean("nssb_gzyq_createJsFileService"); IRuleInfoDao ruleInfoDao = (IRuleInfoDao) rwp .getBean("nssb_gzyq_ruleInfoDao"); // 啟動一個新執行緒執行相應的業務邏輯 new Thread(new CreateRuleJsService(loadRuleService, createJsFileService, ruleInfoDao)).start(); if (logger.isDebugEnabled()) { logger.debug("RuleEngineListener context Initialize end."); } } }
需要配置xml:
<listener>
<listener-class>com.ycjf.ycs.util.genrulejs.RuleEngineListener</listener-class>
</listener>