当前位置: 首页>>代码示例>>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;未经允许,请勿转载。