當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletContextListener.contextInitialized方法代碼示例

本文整理匯總了Java中javax.servlet.ServletContextListener.contextInitialized方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletContextListener.contextInitialized方法的具體用法?Java ServletContextListener.contextInitialized怎麽用?Java ServletContextListener.contextInitialized使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.ServletContextListener的用法示例。


在下文中一共展示了ServletContextListener.contextInitialized方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: contextInitialized

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
public void contextInitialized(ServletContextEvent sce) {
    ctx = WebApplicationContextUtils.getWebApplicationContext(sce
            .getServletContext());

    if (ctx == null) {
        logger.warn("cannot find applicationContext");

        return;
    }

    Collection<ServletContextListener> servletContextListeners = ctx
            .getBeansOfType(ServletContextListener.class).values();

    for (ServletContextListener servletContextListener : servletContextListeners) {
        servletContextListener.contextInitialized(sce);
    }
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:18,代碼來源:ProxyServletListener.java

示例2: testContextLoaderListenerWithDefaultContext

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
@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);
	WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
	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(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
	assertNull(WebApplicationContextUtils.getWebApplicationContext(sc));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:ContextLoaderTests.java

示例3: testContextLoaderWithInvalidContext

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
@Test
public void testContextLoaderWithInvalidContext() throws Exception {
	MockServletContext sc = new MockServletContext("");
	sc.addInitParameter(ContextLoader.CONTEXT_CLASS_PARAM,
			"org.springframework.web.context.support.InvalidWebApplicationContext");
	ServletContextListener listener = new ContextLoaderListener();
	ServletContextEvent event = new ServletContextEvent(sc);
	try {
		listener.contextInitialized(event);
		fail("Should have thrown ApplicationContextException");
	}
	catch (ApplicationContextException ex) {
		// expected
		assertTrue(ex.getCause() instanceof ClassNotFoundException);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:ContextLoaderTests.java

示例4: testServletContextListener

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
private void testServletContextListener(ServletContext servletContext) throws Exception {
    ResteasyAutoConfiguration resteasyAutoConfiguration = new ResteasyAutoConfiguration();
    BeanFactoryPostProcessor beanFactoryPostProcessor = ResteasyAutoConfiguration.springBeanProcessor();
    ServletContextListener servletContextListener = resteasyAutoConfiguration.resteasyBootstrapListener(beanFactoryPostProcessor);
    Assert.assertNotNull(servletContextListener);

    ServletContextEvent sce = new ServletContextEvent(servletContext);
    servletContextListener.contextInitialized(sce);

    ResteasyProviderFactory servletContextProviderFactory = (ResteasyProviderFactory) servletContext.getAttribute(ResteasyProviderFactory.class.getName());
    Dispatcher servletContextDispatcher = (Dispatcher) servletContext.getAttribute(Dispatcher.class.getName());
    Registry servletContextRegistry = (Registry) servletContext.getAttribute(Registry.class.getName());

    Assert.assertNotNull(servletContextProviderFactory);
    Assert.assertNotNull(servletContextDispatcher);
    Assert.assertNotNull(servletContextRegistry);

    // Exercising fully cobertura branch coverage
    servletContextListener.contextDestroyed(sce);
    ServletContextListener servletContextListener2 = resteasyAutoConfiguration.resteasyBootstrapListener(beanFactoryPostProcessor);
    servletContextListener2.contextDestroyed(sce);
}
 
開發者ID:paypal,項目名稱:resteasy-spring-boot,代碼行數:23,代碼來源:ResteasyAutoConfigurationTest.java

示例5: testContextLoaderWithDefaultContextAndParent

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
@Test
public void testContextLoaderWithDefaultContextAndParent() throws Exception {
	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");
	sc.addInitParameter(ContextLoader.LOCATOR_FACTORY_SELECTOR_PARAM,
			"classpath:org/springframework/web/context/ref1.xml");
	sc.addInitParameter(ContextLoader.LOCATOR_FACTORY_KEY_PARAM, "a.qualified.name.of.some.sort");
	ServletContextListener listener = new ContextLoaderListener();
	ServletContextEvent event = new ServletContextEvent(sc);
	listener.contextInitialized(event);
	WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
	assertTrue("Correct WebApplicationContext exposed in ServletContext",
			context 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());
	assertTrue(context.containsBean("beans1.bean1"));
	assertTrue(context.isTypeMatch("beans1.bean1", org.springframework.beans.factory.access.TestBean.class));
	assertTrue(context.containsBean("beans1.bean2"));
	assertTrue(context.isTypeMatch("beans1.bean2", org.springframework.beans.factory.access.TestBean.class));
	listener.contextDestroyed(event);
	assertTrue("Destroyed", lb.isDestroyed());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:28,代碼來源:ContextLoaderTests.java

示例6: testContextLoaderWithCustomContext

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
@Test
public void testContextLoaderWithCustomContext() throws Exception {
	MockServletContext sc = new MockServletContext("");
	sc.addInitParameter(ContextLoader.CONTEXT_CLASS_PARAM,
			"org.springframework.web.servlet.SimpleWebApplicationContext");
	ServletContextListener listener = new ContextLoaderListener();
	ServletContextEvent event = new ServletContextEvent(sc);
	listener.contextInitialized(event);
	WebApplicationContext wc = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
	assertTrue("Correct WebApplicationContext exposed in ServletContext", wc instanceof SimpleWebApplicationContext);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:ContextLoaderTests.java

示例7: testContextLoaderWithInvalidLocation

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
@Test
public void testContextLoaderWithInvalidLocation() throws Exception {
	MockServletContext sc = new MockServletContext("");
	sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "/WEB-INF/myContext.xml");
	ServletContextListener listener = new ContextLoaderListener();
	ServletContextEvent event = new ServletContextEvent(sc);
	try {
		listener.contextInitialized(event);
		fail("Should have thrown BeanDefinitionStoreException");
	}
	catch (BeanDefinitionStoreException ex) {
		// expected
		assertTrue(ex.getCause() instanceof FileNotFoundException);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:16,代碼來源:ContextLoaderTests.java

示例8: testContextLoaderWithDefaultLocation

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
@Test
public void testContextLoaderWithDefaultLocation() throws Exception {
	MockServletContext sc = new MockServletContext("");
	ServletContextListener listener = new ContextLoaderListener();
	ServletContextEvent event = new ServletContextEvent(sc);
	try {
		listener.contextInitialized(event);
		fail("Should have thrown BeanDefinitionStoreException");
	}
	catch (BeanDefinitionStoreException ex) {
		// expected
		assertTrue(ex.getCause() instanceof IOException);
		assertTrue(ex.getCause().getMessage().contains("/WEB-INF/applicationContext.xml"));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:16,代碼來源:ContextLoaderTests.java

示例9: init

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    WebContext.setServlet(this);

    // Call registered WebContextListeners
    for (ServletContextListener contextListener : HANDLER.contextListeners) {
        HANDLER.executeInjection(contextListener);
        contextListener.contextInitialized(new ServletContextEvent(servletConfig.getServletContext()));
    }
}
 
開發者ID:jefalbino,項目名稱:jsmart-web,代碼行數:12,代碼來源:ServletControl.java

示例10: addListener

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
/** Adds a {@link ServletContextListener} to this context and initializes it. */
public MockServletContext addListener(ServletContextListener listener) {
    ServletContextEvent event = new ServletContextEvent(this);
    listener.contextInitialized(event);
    listeners.add(listener);
    return this;
}
 
開發者ID:scarcher2,項目名稱:stripes,代碼行數:8,代碼來源:MockServletContext.java

示例11: contextInitialized

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
public void contextInitialized(ServletContextEvent sce) {
  for (ServletContextListener listener : listeners) {
    listener.contextInitialized(sce);
  }
}
 
開發者ID:bboypscmylife,項目名稱:opengse,代碼行數:6,代碼來源:ServletContextListenerList.java

示例12: addingService

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
@Override
public ServletContextListener addingService(ServiceReference<ServletContextListener> reference) {
  ServletContextListener service = super.addingService(reference);
  service.contextInitialized(new ServletContextEvent(servletContext));
  return service;
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:7,代碼來源:ListenerTracker.java

示例13: contextInitialized

import javax.servlet.ServletContextListener; //導入方法依賴的package包/類
void contextInitialized(ServletContextEvent sce) {
	for (ServletContextListener listeners : bootables) {
		listeners.contextInitialized(sce);
	}
}
 
開發者ID:tamerman,項目名稱:mobile-starting-framework,代碼行數:6,代碼來源:Bootables.java


注:本文中的javax.servlet.ServletContextListener.contextInitialized方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。