Java tutorial
package com.litt.saap.core.web.listener; import java.io.File; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import org.apache.commons.configuration.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.litt.core.common.BeanManager; import com.litt.core.common.ConfigManager; import com.litt.core.common.CoreConstants; import com.litt.saap.core.common.SaapConstants; import com.litt.saap.system.service.ISystemInfoService; import com.litt.saap.system.vo.SystemInfoVo; /** * ??. * * <pre><b>??</b> * ??. * </pre> * * <pre><b></b> * 2014-07-02 ConfigManager?classpath?config.xml, init.properties, system-config.xml * </pre> * * @author <a href="mailto:littcai@hotmail.com">?</a> * @since 2013-9-2 * @version 1.0 */ public class InitSystemListener extends com.litt.core.web.listener.InitSystemListener { /** * Logger for this class */ private static final Logger logger = LoggerFactory.getLogger(InitSystemListener.class); /** * ?. */ public void contextInitialized(ServletContextEvent event) { super.contextInitialized(event); ServletContext application = event.getServletContext(); //HOME? Configuration config = ConfigManager.getInstance().getConfig(); if (config.isEmpty()) { logger.error("???"); throw new java.lang.RuntimeException("???"); } logger.info("?" + config.getString("system.version")); //homePath = props.getProperty("home.path"); String homePath = config.getString("home.path"); CoreConstants.IS_DEBUG = config.getBoolean("debug", false); SaapConstants.HOME_PATH = homePath; //???? logger.info("?" + homePath); File homeFile = new File(homePath); if (!homeFile.exists()) //??? { homeFile.mkdirs(); } //read license. // File licensePath = new File(homePath, "license"); // File licenseFile = new File(licensePath, "license.xml"); // File publicKeyFile = new File(licensePath, "license.key"); // try { // LicenseManager.reload(licenseFile.getPath(), publicKeyFile.getPath()); // } catch (LicenseException e) { // logger.error("Can't read license file.", e); // } String contextPath = application.getContextPath(); //???APPLICATION ISystemInfoService systemInfoService = BeanManager.getBean("systemInfoService", ISystemInfoService.class); SystemInfoVo systemInfoVo = systemInfoService.getSystemInfo(); systemInfoVo.setBaseUrl(config.getString("baseUrl") + contextPath); systemInfoVo.setHomePath(homePath); application.setAttribute(CoreConstants.APP_SYSTEMINFO, systemInfoVo); //servlet? } }