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


Java ContextLoaderListener.contextInitialized方法代碼示例

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


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

示例1: abstractRefreshableWAC_respectsProgrammaticConfigLocations

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
@Test
public void abstractRefreshableWAC_respectsProgrammaticConfigLocations() {
	XmlWebApplicationContext ctx = new XmlWebApplicationContext();
	ctx.setConfigLocation("programmatic.xml");
	ContextLoaderListener cll = new ContextLoaderListener(ctx);

	MockServletContext sc = new MockServletContext();

	try {
		cll.contextInitialized(new ServletContextEvent(sc));
		fail("expected exception");
	} catch (Throwable t) {
		// assert that an attempt was made to load the correct XML
		assertTrue(t.getMessage(), t.getMessage().endsWith(
				"Could not open ServletContext resource [/programmatic.xml]"));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:Spr8510Tests.java

示例2: abstractRefreshableWAC_respectsInitParam_overProgrammaticConfigLocations

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
/**
 * If a contextConfigLocation init-param has been specified for the ContextLoaderListener,
 * then it should take precedence. This is generally not a recommended practice, but
 * when it does happen, the init-param should be considered more specific than the
 * programmatic configuration, given that it still quite possibly externalized in
 * hybrid web.xml + WebApplicationInitializer cases.
 */
@Test
public void abstractRefreshableWAC_respectsInitParam_overProgrammaticConfigLocations() {
	XmlWebApplicationContext ctx = new XmlWebApplicationContext();
	ctx.setConfigLocation("programmatic.xml");
	ContextLoaderListener cll = new ContextLoaderListener(ctx);

	MockServletContext sc = new MockServletContext();
	sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");

	try {
		cll.contextInitialized(new ServletContextEvent(sc));
		fail("expected exception");
	} catch (Throwable t) {
		// assert that an attempt was made to load the correct XML
		assertTrue(t.getMessage(), t.getMessage().endsWith(
				"Could not open ServletContext resource [/from-init-param.xml]"));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:Spr8510Tests.java

示例3: abstractRefreshableWAC_fallsBackToInitParam

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
/**
 * If setConfigLocation has not been called explicitly against the application context,
 * then fall back to the ContextLoaderListener init-param if present.
 */
@Test
public void abstractRefreshableWAC_fallsBackToInitParam() {
	XmlWebApplicationContext ctx = new XmlWebApplicationContext();
	//ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically
	ContextLoaderListener cll = new ContextLoaderListener(ctx);

	MockServletContext sc = new MockServletContext();
	sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");

	try {
		cll.contextInitialized(new ServletContextEvent(sc));
		fail("expected exception");
	} catch (Throwable t) {
		// assert that an attempt was made to load the correct XML
		assertTrue(t.getMessage().endsWith(
				"Could not open ServletContext resource [/from-init-param.xml]"));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:Spr8510Tests.java

示例4: customAbstractRefreshableWAC_fallsBackToInitParam

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
/**
 * Ensure that any custom default locations are still respected.
 */
@Test
public void customAbstractRefreshableWAC_fallsBackToInitParam() {
	XmlWebApplicationContext ctx = new XmlWebApplicationContext() {
		@Override
		protected String[] getDefaultConfigLocations() {
			return new String[] { "/WEB-INF/custom.xml" };
		}
	};
	//ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically
	ContextLoaderListener cll = new ContextLoaderListener(ctx);

	MockServletContext sc = new MockServletContext();
	sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");

	try {
		cll.contextInitialized(new ServletContextEvent(sc));
		fail("expected exception");
	} catch (Throwable t) {
		// assert that an attempt was made to load the correct XML
		System.out.println(t.getMessage());
		assertTrue(t.getMessage().endsWith(
				"Could not open ServletContext resource [/from-init-param.xml]"));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:28,代碼來源:Spr8510Tests.java

示例5: abstractRefreshableWAC_fallsBackToConventionBasedNaming

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
/**
 * If context config locations have been specified neither against the application
 * context nor the context loader listener, then fall back to default values.
 */
@Test
public void abstractRefreshableWAC_fallsBackToConventionBasedNaming() {
	XmlWebApplicationContext ctx = new XmlWebApplicationContext();
	//ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically
	ContextLoaderListener cll = new ContextLoaderListener(ctx);

	MockServletContext sc = new MockServletContext();
	// no init-param set
	//sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");

	try {
		cll.contextInitialized(new ServletContextEvent(sc));
		fail("expected exception");
	} catch (Throwable t) {
		// assert that an attempt was made to load the correct XML
		System.out.println(t.getMessage());
		assertTrue(t.getMessage().endsWith(
				"Could not open ServletContext resource [/WEB-INF/applicationContext.xml]"));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:Spr8510Tests.java

示例6: genericWAC

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
/**
 * Ensure that ContextLoaderListener and GenericWebApplicationContext interact nicely.
 */
@Test
public void genericWAC() {
	GenericWebApplicationContext ctx = new GenericWebApplicationContext();
	ContextLoaderListener cll = new ContextLoaderListener(ctx);

	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
	scanner.scan("bogus.pkg");

	cll.contextInitialized(new ServletContextEvent(new MockServletContext()));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:14,代碼來源:Spr8510Tests.java

示例7: annotationConfigWAC

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
/**
 * Ensure that ContextLoaderListener and AnnotationConfigApplicationContext interact nicely.
 */
@Test
public void annotationConfigWAC() {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();

	ctx.scan("does.not.matter");

	ContextLoaderListener cll = new ContextLoaderListener(ctx);
	cll.contextInitialized(new ServletContextEvent(new MockServletContext()));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:13,代碼來源:Spr8510Tests.java

示例8: setUp

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
protected void setUp() throws Exception {
    super.setUp();
    sc = new MockServletContext("");

    // initialize Spring
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
            "classpath:/applicationContext-dao.xml, " +
            "classpath:/applicationContext-service.xml, " +
            "classpath:/applicationContext-resources.xml");

    springListener = new ContextLoaderListener();
    springListener.contextInitialized(new ServletContextEvent(sc));
    listener = new StartupListener();
}
 
開發者ID:SMVBE,項目名稱:ldadmin,代碼行數:15,代碼來源:StartupListenerTest.java

示例9: onSetUp

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
@Before
public void onSetUp() {
    String appPackage = "org.musicrecital.webapp";
    String appName = "app";


    servletContext = new MockServletContext("");

    // mock servlet settings
    servletContext.addInitParameter(SpringConstants.USE_EXTERNAL_SPRING_CONTEXT, "true");
    servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
            StringUtils.arrayToCommaDelimitedString(locations)
    );

    // Start context loader w/ mock servlet prior to firing off registry
    listener = new ContextLoaderListener();
    listener.contextInitialized(new ServletContextEvent(servletContext));


    tester = new PageTester(appPackage, appName, "src/main/webapp", AppTestModule.class) {
        @Override
        protected ModuleDef[] provideExtraModuleDefs() {
            return new ModuleDef[]{new SpringModuleDef(servletContext)};
        }
    };

    applicationContext = (WebApplicationContext)
            servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

    fieldValues = new HashMap<String, String>();

    smtpPort = smtpPort + (int) (Math.random() * 100);

    // change the port on the mailSender so it doesn't conflict with an
    // existing SMTP server on localhost
    JavaMailSenderImpl mailSender = //(JavaMailSenderImpl)applicationContext.getBean("mailSender");
            applicationContext.getBean(JavaMailSenderImpl.class);
    mailSender.setPort(getSmtpPort());
    mailSender.setHost("localhost");
}
 
開發者ID:dlwhitehurst,項目名稱:musicrecital,代碼行數:41,代碼來源:BasePageTestCase.java

示例10: setUp

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
/**
 * @throws java.lang.Exception
 */
// @Before
public void setUp() throws Exception {
	sc = new MockServletContext("");

	// initialize Spring
	sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
			"classpath:/applicationContext-dao.xml, "
					+ "classpath:/applicationContext-service.xml");

	springListener = new ContextLoaderListener();
	springListener.contextInitialized(new ServletContextEvent(sc));
	listener = new StartupListener();

}
 
開發者ID:Impetus,項目名稱:ankush,代碼行數:18,代碼來源:StartupListenerTest.java

示例11: testLoadContext

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
public void testLoadContext() throws Throwable {

		DaoTestConfigBean bean = new DaoTestConfigBean();
		bean.afterPropertiesSet();

		MockDatabase db = new MockDatabase(true);
		DataSourceFactory.setInstance(db);

		servletContext = new MockServletContext("file:src/main/webapp");

		servletContext.addInitParameter(
				"contextConfigLocation", 
				"classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " +
				"classpath:/META-INF/opennms/applicationContext-soa.xml " +
				"classpath:/META-INF/opennms/applicationContext-dao.xml " +
				"classpath*:/META-INF/opennms/component-service.xml " +
				"classpath*:/META-INF/opennms/component-dao.xml " +
				"/WEB-INF/applicationContext-svclayer.xml " +
				"/WEB-INF/applicationContext-spring-security.xml "
		);

		servletContext.addInitParameter("parentContextKey", "daoContext");

		ServletContextEvent e = new ServletContextEvent(servletContext);
		contextListener = new ContextLoaderListener();
		contextListener.contextInitialized(e);

		servletContext.setContextPath(contextPath);
		servletConfig = new MockServletConfig(servletContext, "dispatcher");    
		servletConfig.addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
		servletConfig.addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest");

		try {

			MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
			filter = new OpenSessionInViewFilter();
			filter.init(filterConfig);
		} catch (ServletException se) {
			throw se.getRootCause();
		}
	}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:42,代碼來源:HttpRemotingContextTest.java

示例12: testLoadContext

import org.springframework.web.context.ContextLoaderListener; //導入方法依賴的package包/類
public void testLoadContext() throws Throwable {

        DaoTestConfigBean bean = new DaoTestConfigBean();
        bean.afterPropertiesSet();

        MockDatabase db = new MockDatabase(true);
        DataSourceFactory.setInstance(db);

        servletContext = new MockServletContext("file:src/main/webapp");

        servletContext.addInitParameter("contextConfigLocation", 
                                        "classpath:/org/opennms/web/rest/applicationContext-test.xml " +
                                        "classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " +
                                        "classpath*:/META-INF/opennms/component-service.xml " +
                                        "classpath*:/META-INF/opennms/component-dao.xml " +
                                        "classpath:/META-INF/opennms/applicationContext-reportingCore.xml " +
                                        "classpath:/org/opennms/web/svclayer/applicationContext-svclayer.xml " +
                                        "classpath:/META-INF/opennms/applicationContext-reporting.xml " +
                                        "/WEB-INF/applicationContext-spring-security.xml " +
                                        "/WEB-INF/applicationContext-spring-webflow.xml"
        );

        servletContext.addInitParameter("parentContextKey", "daoContext");

        ServletContextEvent e = new ServletContextEvent(servletContext);
        contextListener = new ContextLoaderListener();
        contextListener.contextInitialized(e);

        servletContext.setContextPath(contextPath);
        servletConfig = new MockServletConfig(servletContext, "dispatcher");    
        servletConfig.addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
        servletConfig.addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest");

        try {

            MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
            filter = new OpenSessionInViewFilter();        
            filter.init(filterConfig);

            dispatcher = new SpringServlet();
            dispatcher.init(servletConfig);

        } catch (ServletException se) {
            throw se.getRootCause();
        }
    }
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:47,代碼來源:SpringWebflowContextTest.java


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