当前位置: 首页>>代码示例>>Java>>正文


Java ContextLoaderListener类代码示例

本文整理汇总了Java中org.springframework.web.context.ContextLoaderListener的典型用法代码示例。如果您正苦于以下问题:Java ContextLoaderListener类的具体用法?Java ContextLoaderListener怎么用?Java ContextLoaderListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContextLoaderListener类属于org.springframework.web.context包,在下文中一共展示了ContextLoaderListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startServer

import org.springframework.web.context.ContextLoaderListener; //导入依赖的package包/类
private static void startServer() throws Exception, InterruptedException {
  Server server = new Server(port);
  Context context = new Context(server, "/", Context.SESSIONS);
  context.addServlet(DefaultServlet.class, "/*");

  context.addEventListener(new ContextLoaderListener(getContext()));
  context.addEventListener(new RequestContextListener());

  WicketFilter filter = new WicketFilter();
  filter.setFilterPath("/");
  FilterHolder holder = new FilterHolder(filter);
  holder.setInitParameter("applicationFactoryClassName", APP_FACTORY_NAME);
  context.addFilter(holder, "/*", Handler.DEFAULT);

  server.setHandler(context);
  server.start();
  server.join();
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:19,代码来源:NutchUiServer.java

示例2: onStartup

import org.springframework.web.context.ContextLoaderListener; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	WebApplicationContext context = getContext();
	servletContext.addListener(new ContextLoaderListener(context));
	servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter("UTF-8"));

	DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
	dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);

	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("Dispatcher", dispatcherServlet);
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/*");

	CXFServlet cxf = new CXFServlet();
	BusFactory.setDefaultBus(cxf.getBus());
	ServletRegistration.Dynamic cxfServlet = servletContext.addServlet("CXFServlet", cxf);
	cxfServlet.setLoadOnStartup(1);
	cxfServlet.addMapping("/services/*");

	servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(null, false,
			"/*");

	servletContext.getSessionCookieConfig().setSecure(cookieSecure);
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:25,代码来源:AppInitializer.java

示例3: onStartup

import org.springframework.web.context.ContextLoaderListener; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    //On charge le contexte de l'app
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setDisplayName("scrumtracker");
    rootContext.register(ApplicationContext.class);

    //Context loader listener
    servletContext.addListener(new ContextLoaderListener(rootContext));

    //Dispatcher servlet
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
}
 
开发者ID:scrumtracker,项目名称:scrumtracker2017,代码行数:17,代码来源:ApplicationInitializer.java

示例4: onStartup

import org.springframework.web.context.ContextLoaderListener; //导入依赖的package包/类
/**
 * Configure the given {@link ServletContext} with any servlets, filters, listeners
 * context-params and attributes necessary for initializing this web application. See examples
 * {@linkplain WebApplicationInitializer above}.
 *
 * @param servletContext the {@code ServletContext} to initialize
 * @throws ServletException if any call against the given {@code ServletContext} throws a {@code ServletException}
 */
public void onStartup(ServletContext servletContext) throws ServletException {
	// Spring Context Bootstrapping
	AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext();
	rootAppContext.register(AutoPivotConfig.class);
	servletContext.addListener(new ContextLoaderListener(rootAppContext));

	// Set the session cookie name. Must be done when there are several servers (AP,
	// Content server, ActiveMonitor) with the same URL but running on different ports.
	// Cookies ignore the port (See RFC 6265).
	CookieUtil.configure(servletContext.getSessionCookieConfig(), CookieUtil.COOKIE_NAME);

	// The main servlet/the central dispatcher
	final DispatcherServlet servlet = new DispatcherServlet(rootAppContext);
	servlet.setDispatchOptionsRequest(true);
	Dynamic dispatcher = servletContext.addServlet("springDispatcherServlet", servlet);
	dispatcher.addMapping("/*");
	dispatcher.setLoadOnStartup(1);

	// Spring Security Filter
	final FilterRegistration.Dynamic springSecurity = servletContext.addFilter(SPRING_SECURITY_FILTER_CHAIN, new DelegatingFilterProxy());
	springSecurity.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

}
 
开发者ID:activeviam,项目名称:autopivot,代码行数:32,代码来源:AutoPivotWebAppInitializer.java

示例5: onStartup

import org.springframework.web.context.ContextLoaderListener; //导入依赖的package包/类
@Override
public void onStartup(ServletContext container) {
	// Create the 'root' Spring application context
	AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
	rootContext.register(AppConfig.class);

	// Manage the lifecycle of the root application context
	container.addListener(new ContextLoaderListener(rootContext));

	// Create the dispatcher servlet's Spring application context
	AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();

	// Register and map the dispatcher servlet
	ServletRegistration.Dynamic dispatcher = container
			.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/");
}
 
开发者ID:auth0-blog,项目名称:embedded-spring-5,代码行数:19,代码来源:AppConfig.java

示例6: onStartup

import org.springframework.web.context.ContextLoaderListener; //导入依赖的package包/类
@Override
public void onStartup(ServletContext sc) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(AppConfig.class);

    sc.addListener(new ContextLoaderListener(context));
    sc.setInitParameter("defaultHtmlEscape", "true");

    ServletRegistration.Dynamic dispatcher = sc.addServlet("dispatcherServlet", new DispatcherServlet(context));

    dispatcher.setLoadOnStartup(1);
    dispatcher.setAsyncSupported(true);
    dispatcher.addMapping("/");

    FilterRegistration.Dynamic securityFilter = sc.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class);
    securityFilter.addMappingForUrlPatterns(null, false, "/*");
    securityFilter.setAsyncSupported(true);
}
 
开发者ID:ortolanph,项目名称:hojeehdiaderua,代码行数:19,代码来源:DiaDeRuaWebInitializer.java

示例7: initWebApp

import org.springframework.web.context.ContextLoaderListener; //导入依赖的package包/类
private WebAppContext initWebApp() throws IOException {
    WebAppContext ctx = new WebAppContext();
    ctx.setContextPath(CONFIG.getContextPath());
    ctx.setResourceBase(new ClassPathResource("webapp").getURI().toString());

    // Disable directory listings if no index.html is found.
    ctx.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");

    ServletHolder web = new ServletHolder("spring-dispatcher", new DispatcherServlet(springContext));
    ServletHolder cxf = new ServletHolder("cxf", new CXFServlet());

    ctx.addEventListener(new ContextLoaderListener(springContext));
    ctx.addServlet(web, CONFIG.getSpringMapping());
    ctx.addServlet(cxf, CONFIG.getCxfMapping());

    if (CONFIG.getProfile().isProd()) {
        addSecurityFilter(ctx);
    }

    initJSP(ctx);
    return ctx;
}
 
开发者ID:RWTH-i5-IDSG,项目名称:steve-plugsurfing,代码行数:23,代码来源:SteveAppContext.java

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: onStartup

import org.springframework.web.context.ContextLoaderListener; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	servletContext.getServletRegistration("default").addMapping("/resources/*");

	AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
	rootContext.register(RootApplicationContextConfig.class);
	servletContext.addListener(new ContextLoaderListener(rootContext));

	AnnotationConfigWebApplicationContext servletContextConfig = new AnnotationConfigWebApplicationContext();
	servletContextConfig.register(ServletApplicationContextConfig.class);
	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("springDispatcher",
			new DispatcherServlet(servletContextConfig));

	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/");

	FilterRegistration.Dynamic registration = servletContext.addFilter("preSecFilter", new PreSescLoggingFilter());
	registration.addMappingForUrlPatterns(null, false, "/*");

	FilterRegistration.Dynamic reg = servletContext.addFilter("encoding",
			new CharacterEncodingFilter("UTF-8", true));
	reg.addMappingForUrlPatterns(null, false, "/*");
}
 
开发者ID:shilongdai,项目名称:bookManager,代码行数:24,代码来源:SpringBootStrap.java

示例14: onStartup

import org.springframework.web.context.ContextLoaderListener; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    log.debug("Initializing servlet application context");
    AnnotationConfigWebApplicationContext servletAppContext = new AnnotationConfigWebApplicationContext();

    // register webapp spring configuration
    servletAppContext.register(SpringInitializer.class);

    log.debug("Registering Spring ContextLoaderListener");
    registerListener(servletContext, new ContextLoaderListener(servletAppContext));

    log.debug("Registering Spring DispatcherServlet");
    registerServlet(servletContext, new DispatcherServlet(servletAppContext), "/").setLoadOnStartup(1);

    loadActiveSpringProfiles(servletContext, servletAppContext);
}
 
开发者ID:sdl,项目名称:ecommerce-framework,代码行数:17,代码来源:WebAppInitializer.java

示例15: onStartup

import org.springframework.web.context.ContextLoaderListener; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	// Logger initialization is deferred in case a ordered
	// LogServletContextInitializer is being used
	this.logger = LogFactory.getLog(getClass());
	WebApplicationContext rootAppContext = createRootApplicationContext(
			servletContext);
	if (rootAppContext != null) {
		servletContext.addListener(new ContextLoaderListener(rootAppContext) {
			@Override
			public void contextInitialized(ServletContextEvent event) {
				// no-op because the application context is already initialized
			}
		});
	}
	else {
		this.logger.debug("No ContextLoaderListener registered, as "
				+ "createRootApplicationContext() did not "
				+ "return an application context");
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:SpringBootServletInitializer.java


注:本文中的org.springframework.web.context.ContextLoaderListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。