下面列出了javax.servlet.ServletContextEvent#getServletContext ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void contextInitialized(ServletContextEvent servletContextEvent) {
this.context = servletContextEvent.getServletContext();
String log4jConfig = context.getInitParameter("log4j.config");
if (log4jConfig != null && !log4jConfig.isEmpty()) {
System.out.println("[HMDM-LOGGING] : Using log4j configuration from: " + log4jConfig);
System.setProperty("log4j.configuration", log4jConfig);
System.setProperty("log4j.ignoreTCL", "true");
} else {
System.out.println("[HMDM-LOGGING] Using log4j configuration from build");
}
super.contextInitialized(servletContextEvent);
initTasks();
}
/**
* context初始化.
*/
@Override
public void contextInitialized(ServletContextEvent event) {
System.out.println("contextInitialized");
ServletContext servletContext = event.getServletContext();
if (null == this.context) {
//配置的application文件路径
String cfgFile = servletContext.getInitParameter("contextConfigLocation");
this.context = new WebApplicationContext(cfgFile);
//存入上下文,后面servlet会取用
servletContext.setAttribute(ROOT_CXT_ATTR, this.context);
}
//源码中是在这里初始化context,调用refresh方法的,我们在上面new的时候先做了
// initWebApplicationContext(this.context);
}
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
servletContext = sc;
// Try and use one of the Servlet 3.0 methods that should be blocked
try {
sc.getEffectiveMajorVersion();
log.append("FAIL-01");
} catch (UnsupportedOperationException uoe) {
log.append("PASS-01");
} catch (Exception e) {
log.append("FAIL-02");
}
}
@Override
public void contextInitialized( ServletContextEvent event) {
ServletContext servletContext = event.getServletContext();
String reportDesignPath = servletContext.getRealPath( ComExtensionConstants.PLUGIN_BIRT_RPTDESIGN_BASE);
String scriptlibPath = servletContext.getRealPath(ComExtensionConstants.PLUGIN_BIRT_SCRIPTLIB_BASE);
String pluginsPath;
try {
pluginsPath = ConfigService.getInstance().getValue(ConfigValue.EmmPluginsHome);
} catch (Exception e) {
logger.error("Cannot read EmmPluginsHome: " + e.getMessage(), e);
throw new RuntimeException("Cannot read EmmPluginsHome: " + e.getMessage(), e);
}
if( logger.isDebugEnabled()) {
logger.debug( "Path for report designs: " + reportDesignPath);
logger.debug( "Path for script libs: " + scriptlibPath);
logger.debug( "Path for plugin ZIPs: " + pluginsPath);
}
BirtPluginInstaller installer = new BirtPluginInstaller( pluginsPath, reportDesignPath, scriptlibPath);
installer.installPlugins();
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
try {
ServletContext servletContext = servletContextEvent.getServletContext();
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
ExecutorService workerExecutorService = (ExecutorService) webApplicationContext.getBean("WorkerExecutorService");
Thread.sleep(1000);
logger.info("Shutting down WorkerExecutorService");
int retryCount = 0;
while (!workerExecutorService.isTerminated() && retryCount < 10) {
if (retryCount > 0) {
logger.error("WorkerExecutorService shutdown retryCount: " + retryCount);
Thread.sleep(1000);
}
workerExecutorService.shutdownNow();
retryCount++;
}
} catch (Exception e) {
logger.error("Cannot shutdown WorkerExecutorService: " + e.getMessage(), e);
}
}
@Override
public void contextInitialized(ServletContextEvent event) {
try {
// Birt must generate messages in here, because it has no struts like EMM
// Messages are then available via I18nString
DBMessagesResource dbMessagesResource = new DBMessagesResource();
dbMessagesResource.init();
ServletContext servletContext = event.getServletContext();
if (ConfigService.getInstance().getBooleanValue(ConfigValue.IsLiveInstance)) {
createMessagesPropertiesFiles(servletContext);
}
} catch (Exception e) {
logger.error("MessagesPropertiesGeneratorContextListener init: " + e.getMessage(), e);
}
}
@Override
public void contextInitialized(ServletContextEvent evt) {
ServletContext sc = evt.getServletContext();
//项目发布,当前运行环境的绝对路径
conf.put("realPath", sc.getRealPath("/").replaceFirst("/", ""));
//servletContextPath,默认""
conf.put("contextPath", sc.getContextPath());
}
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
// Don't trigger WebSocket initialization if a WebSocket Server
// Container is already present
if (sc.getAttribute(Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE) == null) {
WsSci.init(sce.getServletContext(), false);
}
}
@Override
public void contextInitialized(ServletContextEvent evt) {
ServletContext sc = evt.getServletContext();
// 项目路径
conf.put("realPath", sc.getRealPath("/").replaceFirst("/", ""));
conf.put("contextPath", sc.getContextPath());
}
@Override
public void contextInitialized(ServletContextEvent evt) {
ServletContext sc = evt.getServletContext();
//项目发布,当前运行环境的绝对路径
conf.put("realPath", sc.getRealPath("/").replaceFirst("/", ""));
//servletContextPath,默认""
conf.put("contextPath", sc.getContextPath());
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// Bug 57446. Same ServletContext should be presented as at init
if (servletContext == sce.getServletContext()) {
log.append("PASS-02");
} else {
//log.append("FAIL-03");
}
}
@Override
public void contextInitialized(ServletContextEvent sce) {
/**
* 注册服务单例
*/
ServletContext sc = sce.getServletContext();
UserService userService = (UserService) BeanFactory.getBean(BeanFactory.ServiceType.UserService);
sc.setAttribute("userService",userService);
RoomService roomService = (RoomService) BeanFactory.getBean(BeanFactory.ServiceType.RoomService);
sc.setAttribute("roomService",roomService);
OrderRoomService orderRoomService = (OrderRoomService)BeanFactory.getBean(BeanFactory.ServiceType.OrderRoomService);
sc.setAttribute("orderRoomService",orderRoomService);
RemarkService remarkService = (RemarkService) BeanFactory.getBean((BeanFactory.ServiceType.RemarkService));
sc.setAttribute("remarkService",remarkService);
}
@Override
public final void contextInitialized(final ServletContextEvent servletContextEvent) {
final ServletContext servletContext = servletContextEvent.getServletContext();
webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
updateMarkedCompanies();
}
@Override
public void contextDestroyed(ServletContextEvent event) {
ServletContext servletContext = event.getServletContext();
ExtensionSystemImpl extensionSystem = (ExtensionSystemImpl) servletContext.getAttribute(ExtensionConstants.EXTENSION_SYSTEM_APPLICATION_SCOPE_ATTRIBUTE);
if (extensionSystem != null) {
logger.info( "Shutting down ExtensionSystem");
extensionSystem.shutdown();
logger.info( "ExtensionSystem is shut down");
}
}
@Override
public void contextInitialized(ServletContextEvent event) {
try {
ServletContext servletContext = event.getServletContext();
ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
DBase.DATASOURCE = (DataSource) applicationContext.getBean("dataSource");
if (DBase.DATASOURCE == null) {
logger.error("Datasource in DBase for Backend was empty. Backend will try to create its own datasource from emm.properties data");
}
} catch (Exception e) {
logger.error("Cannot set Datasource in DBase for Backend. Backend will try to create its own datasource from emm.properties data", e);
}
}
@Override
public void contextInitialized(ServletContextEvent sce) {
Stockticker stockticker = new Stockticker();
ServletContext sc = sce.getServletContext();
sc.setAttribute(STOCK_TICKER_KEY, stockticker);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
Stockticker stockticker = (Stockticker) sc.getAttribute(STOCK_TICKER_KEY);
stockticker.shutdown();
}
@Override
public void contextInitialized(ServletContextEvent sce) {
Stockticker stockticker = new Stockticker();
ServletContext sc = sce.getServletContext();
sc.setAttribute(STOCK_TICKER_KEY, stockticker);
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
ServletContext servletContext = arg0.getServletContext();
System.out.println("UserListener...contextInitialized...");
}
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
sc.addListener(SCL3.class.getName());
}