javax.servlet.ServletContextListener.contextDestroyed()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中javax.servlet.ServletContextListener.contextDestroyed()方法的一些代码示例,展示了ServletContextListener.contextDestroyed()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServletContextListener.contextDestroyed()方法的具体详情如下:
包路径:javax.servlet.ServletContextListener
类名称:ServletContextListener
方法名:contextDestroyed

ServletContextListener.contextDestroyed介绍

[英]Receives notification that the ServletContext is about to be shut down.

All servlets and filters will have been destroyed before any ServletContextListeners are notified of context destruction.
[中]接收ServletContext即将关闭的通知。
在任何ServletContextListeners收到上下文破坏通知之前,所有Servlet和过滤器都将被销毁。

代码示例

代码示例来源:origin: org.freemarker/freemarker

public void contextDestroyed(ServletContextEvent arg0) {
  synchronized (servletContextListeners) {
    int s = servletContextListeners.size();
    for (int i = s - 1; i >= 0; --i) {
      ((ServletContextListener) servletContextListeners.get(i)).contextDestroyed(arg0);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testContextLoaderListenerWithDefaultContext() {
  MockServletContext sc = new MockServletContext("");
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
      "/org/springframework/web/context/WEB-INF/applicationContext.xml " +
      "/org/springframework/web/context/WEB-INF/context-addition.xml");
  ServletContextListener listener = new ContextLoaderListener();
  ServletContextEvent event = new ServletContextEvent(sc);
  listener.contextInitialized(event);
  String contextAttr = WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;
  WebApplicationContext context = (WebApplicationContext) sc.getAttribute(contextAttr);
  assertTrue("Correct WebApplicationContext exposed in ServletContext", context instanceof XmlWebApplicationContext);
  assertTrue(WebApplicationContextUtils.getRequiredWebApplicationContext(sc) instanceof XmlWebApplicationContext);
  LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle");
  assertTrue("Has father", context.containsBean("father"));
  assertTrue("Has rod", context.containsBean("rod"));
  assertTrue("Has kerry", context.containsBean("kerry"));
  assertTrue("Not destroyed", !lb.isDestroyed());
  assertFalse(context.containsBean("beans1.bean1"));
  assertFalse(context.containsBean("beans1.bean2"));
  listener.contextDestroyed(event);
  assertTrue("Destroyed", lb.isDestroyed());
  assertNull(sc.getAttribute(contextAttr));
  assertNull(WebApplicationContextUtils.getWebApplicationContext(sc));
}

代码示例来源:origin: haraldk/TwelveMonkeys

@Test
public void testContextDestroyed() {
  ServletContext context = mock(ServletContext.class);
  ServletContextEvent destroyed = mock(ServletContextEvent.class);
  when(destroyed.getServletContext()).thenReturn(context);
  ServletContextListener listener = new IIOProviderContextListener();
  listener.contextInitialized(mock(ServletContextEvent.class));
  listener.contextDestroyed(destroyed);
}

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

@Override
protected void fireUndeployEvent() {
  if (_servletContextListeners != null) {
    ServletContextEvent servletContextEvent = new ServletContextEvent(
      servletContext);
    for (ServletContextListener servletContextListener :
        _servletContextListeners) {
      try {
        servletContextListener.contextDestroyed(
          servletContextEvent);
      }
      catch (Throwable t) {
        String className = ClassUtil.getClassName(
          servletContextListener.getClass());
        _log.error(
          StringBundler.concat(
            className, " is unable to process a context ",
            "destroyed event for ",
            servletContext.getServletContextName()),
          t);
      }
    }
  }
  super.fireUndeployEvent();
}

代码示例来源:origin: org.tinygroup/org.tinygroup.weblayerbase

private void stopListeners() {
  for (ServletContextListener listener : listeners) {
    listener.contextDestroyed(event);
  }
}

代码示例来源:origin: org.tinygroup/weblayer

private void stopListeners() {
  for (ServletContextListener listener : listeners) {
    listener.contextDestroyed(event);
  }
}

代码示例来源:origin: com.vaadin/flow-server

@Override
public void contextDestroyed(ServletContextEvent sce) {
  for (ServletContextListener listener : listeners) {
    listener.contextDestroyed(sce);
  }
}

代码示例来源:origin: org.apache.myfaces.test/myfaces-test22

public void contextDestroyed(ServletContextEvent sce)
{
  if (contextListeners != null && !contextListeners.isEmpty())
  {
    for (ServletContextListener listener : contextListeners)
    {
      listener.contextDestroyed(sce);
    }
  }
}

代码示例来源:origin: haraldk/TwelveMonkeys

@Test
public void testDestroyConcurrentModRegression() {
  ServletContext context = mock(ServletContext.class);
  ServletContextEvent destroyed = mock(ServletContextEvent.class);
  when(destroyed.getServletContext()).thenReturn(context);
  ServletContextListener listener = new IIOProviderContextListener();
  listener.contextInitialized(mock(ServletContextEvent.class));
  ImageReaderSpi provider1 = new MockImageReaderSpiOne();
  ImageReaderSpi provider2 = new MockImageReaderSpiToo();
  // NOTE: Fake registering for simplicity, but it still exposes the original problem with de-registering
  IIORegistry registry = IIORegistry.getDefaultInstance();
  registry.registerServiceProvider(provider1);
  registry.registerServiceProvider(provider2);
  assertTrue(registry.contains(provider1));
  assertTrue(registry.contains(provider2));
  listener.contextDestroyed(destroyed);
  assertFalse(registry.contains(provider1));
  assertFalse(registry.contains(provider2));
}

代码示例来源:origin: org.freemarker/com.springsource.freemarker

public void contextDestroyed(ServletContextEvent arg0)
{
  synchronized(servletContextListeners)
  {
    int s = servletContextListeners.size();
    for(int i = s - 1; i >= 0; --i)
    {
      ((ServletContextListener)servletContextListeners.get(i)).contextDestroyed(arg0);
    }
  }
}

代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9

public void contextDestroyed(ServletContextEvent sce)
{
  if (_tldListeners == null)
    return;
  for (int i=_tldListeners.size()-1; i>=0; i--) {
    EventListener l = _tldListeners.get(i);
    if (l instanceof ServletContextListener) {
      ((ServletContextListener)l).contextDestroyed(sce);
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-web

@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
  super.contextDestroyed(servletContextEvent);
  if (webServletContextListener != null) {
    webServletContextListener.contextDestroyed(servletContextEvent);
  }
}

代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9

protected void callContextDestroyed (ServletContextListener l, ServletContextEvent e)
{
  LOG.debug("contextDestroyed: {}->{}",e,l);
  l.contextDestroyed(e);
}

代码示例来源:origin: zycgit/hasor

public void contextDestroyed(final ServletContextEvent event) {
    ServletContextListener servletContextListener = this.getTarget();
    if (servletContextListener != null) {
      servletContextListener.contextDestroyed(event);
    }
  }
}

代码示例来源:origin: net.sourceforge.stripes/stripes

/**Removes and destroys all registered {@link ServletContextListener}. */
public MockServletContext removeListeners() {
  ServletContextEvent e = new ServletContextEvent(this);
  for (ServletContextListener l : listeners) {
    l.contextDestroyed(e);
  }
  listeners.clear();
  return this;
}

代码示例来源:origin: httpunit/httpunit

private void notifyContextDestroyed() {
  ServletContextEvent event = new ServletContextEvent( getServletContext() );
  for (ListIterator i = _contextListeners.listIterator( _contextListeners.size() ); i.hasPrevious();) {
    ServletContextListener listener = (ServletContextListener) i.previous();
    listener.contextDestroyed( event );
  }
}

代码示例来源:origin: org.kohsuke.httpunit/httpunit

private void notifyContextDestroyed() {
  ServletContextEvent event = new ServletContextEvent( getServletContext() );
  for (ListIterator i = _contextListeners.listIterator( _contextListeners.size() ); i.hasPrevious();) {
    ServletContextListener listener = (ServletContextListener) i.previous();
    listener.contextDestroyed( event );
  }
}

代码示例来源:origin: sonatype/nexus-public

@Override
 public void removedService(ServiceReference<ServletContextListener> reference, ServletContextListener service) {
  service.contextDestroyed(new ServletContextEvent(servletContext));
  super.removedService(reference, service);
 }
}

代码示例来源:origin: Nextdoor/bender

protected void callContextDestroyed (ServletContextListener l, ServletContextEvent e)
{
  if (LOG.isDebugEnabled())
    LOG.debug("contextDestroyed: {}->{}",e,l);
  l.contextDestroyed(e);
}

代码示例来源:origin: org.sonatype.nexus/nexus-bootstrap

@Override
 public void removedService(ServiceReference<ServletContextListener> reference, ServletContextListener service) {
  service.contextDestroyed(new ServletContextEvent(servletContext));
  super.removedService(reference, service);
 }
}

相关文章