applicationlistener.java

来自「一个很好的开源项目管理系统源代码」· Java 代码 · 共 90 行

JAVA
90
字号
package net.java.workeffort.webapp.support;import javax.servlet.ServletContext;import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;import net.java.workeffort.service.IListOfValuesService;import net.java.workeffort.webapp.security.RoleManager;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.springframework.web.context.ContextLoaderListener;import org.springframework.web.context.WebApplicationContext;import org.springframework.web.context.support.WebApplicationContextUtils;/** * The application Listener. This is configured in the web.xml file. It * initializes the spring context, initializes the security roles for the * application and primes the list of values data. * @author Antony Joseph */public class ApplicationListener extends ContextLoaderListener implements        ServletContextListener {    private static final Log logger = LogFactory.getLog(ApplicationListener.class);    public void contextInitialized(ServletContextEvent sce) {        if (logger.isInfoEnabled()) {            logger.info("Initializing context");        }        // initialize the spring context        super.contextInitialized(sce);        // initialize the application.        initializeApplication(sce.getServletContext());    }    public void initializeApplication(ServletContext servletContext) {        WebApplicationContext wac = WebApplicationContextUtils                .getRequiredWebApplicationContext(servletContext);        // load all roles and corresponding permissions        RoleManager roleManager = (RoleManager) wac.getBean("roleManager");        roleManager.initialize();        // Store the list of values service in application scope.        IListOfValuesService lovService = (IListOfValuesService) wac                .getBean("listOfValuesService");        primeListOfValues(lovService);        logger.info("Application initialization successful.");    }    /**     * Even if we don't prime the list of values, the system will work because     * the caching scheme will cache the lovs as they are accessed.     * @param lovService The lov service     */    private  void primeListOfValues(IListOfValuesService lovService) {        lovService.getCachedRequirementTypeLov();        lovService.getCachedWorkTypeLov();        lovService.getCachedWorkStatusLov();        lovService.getCachedWorkPurposeTypeLov();        lovService.getCachedWorkAssociationTypeLov();        lovService.getCachedWorkRoleLov();        lovService.getCachedWorkFxdastAsgnStatusLov();        lovService.getCachedPartTypeLov();        lovService.getCachedFixedAssetTypeLov();        lovService.getCachedSkillTypeLov();        lovService.getCachedDeliverableTypeLov();        lovService.getCachedPartStatusLov();        lovService.getCachedPartyTypeLov();        lovService.getCachedFacilityTypeLov();        lovService.getCachedTargetTypeLov();        lovService.getCachedRateTypeLov();        lovService.getCachedCurrencyLov();        lovService.getCachedYesNoLov();        lovService.getCachedTimesheetApprovalLov();        lovService.getCachedDeliverableLov();        lovService.getCachedFixedAssetLov();        lovService.getCachedProductLov();        lovService.getCachedFacilityLov();        lovService.getCachedSkillLov();        lovService.getCachedRoleLov();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?