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


Java ConfigurableWebApplicationContext.setParent方法代碼示例

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


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

示例1: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
/**
 * Instantiate the WebApplicationContext for this servlet, either a default
 * {@link org.springframework.web.context.support.XmlWebApplicationContext}
 * or a {@link #setContextClass custom context class}, if set.
 * <p>This implementation expects custom contexts to implement the
 * {@link org.springframework.web.context.ConfigurableWebApplicationContext}
 * interface. Can be overridden in subclasses.
 * <p>Do not forget to register this servlet instance as application listener on the
 * created context (for triggering its {@link #onRefresh callback}, and to call
 * {@link org.springframework.context.ConfigurableApplicationContext#refresh()}
 * before returning the context instance.
 * @param parent the parent ApplicationContext to use, or {@code null} if none
 * @return the WebApplicationContext for this servlet
 * @see org.springframework.web.context.support.XmlWebApplicationContext
 */
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
	Class<?> contextClass = getContextClass();
	if (this.logger.isDebugEnabled()) {
		this.logger.debug("Servlet with name '" + getServletName() +
				"' will try to create custom WebApplicationContext context of class '" +
				contextClass.getName() + "'" + ", using parent context [" + parent + "]");
	}
	if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
		throw new ApplicationContextException(
				"Fatal initialization error in servlet with name '" + getServletName() +
				"': custom WebApplicationContext class [" + contextClass.getName() +
				"] is not of type ConfigurableWebApplicationContext");
	}
	ConfigurableWebApplicationContext wac =
			(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);

	wac.setEnvironment(getEnvironment());
	wac.setParent(parent);
	wac.setConfigLocation(getContextConfigLocation());

	configureAndRefreshWebApplicationContext(wac);

	return wac;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:40,代碼來源:FrameworkServlet.java

示例2: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
@Override
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Servlet with name '" + getServletName() +
                "' will try to create custom WebApplicationContext context of class '" +
                CubaXmlWebApplicationContext.class.getName() + "'" + ", using parent context [" + parent + "]");
    }
    ConfigurableWebApplicationContext wac = new CubaXmlWebApplicationContext() {
        @Override
        protected ResourcePatternResolver getResourcePatternResolver() {
            if (dependencyJars == null || dependencyJars.isEmpty()) {
                throw new RuntimeException("No JARs defined for the 'web' block. " +
                        "Please check that web.dependencies file exists in WEB-INF directory.");
            }
            return new SingleAppResourcePatternResolver(this, dependencyJars);
        }
    };

    wac.setEnvironment(getEnvironment());
    wac.setParent(parent);
    wac.setConfigLocation(getContextConfigLocation());

    configureAndRefreshWebApplicationContext(wac);

    return wac;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:27,代碼來源:SingleAppDispatcherServlet.java

示例3: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
    Class<?> contextClass = getContextClass();
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Servlet with name '" + getServletName() +
                "' will try to create custom WebApplicationContext context of class '" +
                contextClass.getName() + "'" + ", using parent context [" + parent + "]");
    }
    if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
        throw new ApplicationContextException(
                "Fatal initialization error in servlet with name '" + getServletName() +
                "': custom WebApplicationContext class [" + contextClass.getName() +
                "] is not of type ConfigurableWebApplicationContext");
    }
    ConfigurableWebApplicationContext wac =
            (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
    
    wac.setParent(parent);
    if (wac.getParent() == null) {
        ApplicationContext rootContext = (ApplicationContext) getServletContext().getAttribute("JetStreamRoot");
        wac.setParent(rootContext);
    }
    wac.setConfigLocation(getContextConfigLocation());
    configureAndRefreshWebApplicationContext(wac);
    return wac;
}
 
開發者ID:pulsarIO,項目名稱:realtime-analytics,代碼行數:26,代碼來源:MetricDispatcherServlet.java

示例4: postProcessWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
@Override
protected void postProcessWebApplicationContext(ConfigurableWebApplicationContext wac) {
    if (wac instanceof MotechOSGiWebApplicationContext) {
        MotechOSGiWebApplicationContext wc = (MotechOSGiWebApplicationContext) wac;
        wc.setBundleContext(bundleContext);
        if (configurableWebApplicationContext != null) {
            configurableWebApplicationContext.setServletContext(getServletContext());
            wac.setParent(configurableWebApplicationContext);
        }
    }
    super.postProcessWebApplicationContext(wac);
}
 
開發者ID:motech,項目名稱:motech,代碼行數:13,代碼來源:OSGiDispatcherServlet.java

示例5: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
/**
 * Instantiate the WebApplicationContext for the ActionServlet, either a default
 * XmlWebApplicationContext or a custom context class if set.
 * <p>This implementation expects custom contexts to implement ConfigurableWebApplicationContext.
 * Can be overridden in subclasses.
 * @throws org.springframework.beans.BeansException if the context couldn't be initialized
 * @see #setContextClass
 * @see org.springframework.web.context.support.XmlWebApplicationContext
 */
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
		throws BeansException {

	if (logger.isDebugEnabled()) {
		logger.debug("ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() +
				"', module '" + getModulePrefix() + "' will try to create custom WebApplicationContext " +
				"context of class '" + getContextClass().getName() + "', using parent context [" + parent + "]");
	}
	if (!ConfigurableWebApplicationContext.class.isAssignableFrom(getContextClass())) {
		throw new ApplicationContextException(
				"Fatal initialization error in ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() +
				"', module '" + getModulePrefix() + "': custom WebApplicationContext class [" +
				getContextClass().getName() + "] is not of type ConfigurableWebApplicationContext");
	}

	ConfigurableWebApplicationContext wac =
			(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(getContextClass());
	wac.setParent(parent);
	wac.setServletContext(getServletContext());
	wac.setNamespace(getNamespace());
	if (getContextConfigLocation() != null) {
		wac.setConfigLocations(
			StringUtils.tokenizeToStringArray(
						getContextConfigLocation(), ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
	}
	wac.addBeanFactoryPostProcessor(
			new BeanFactoryPostProcessor() {
				public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
					beanFactory.addBeanPostProcessor(new ActionServletAwareProcessor(getActionServlet()));
					beanFactory.ignoreDependencyType(ActionServlet.class);
				}
			}
	);

	wac.refresh();
	return wac;
}
 
開發者ID:Gert-Jan1966,項目名稱:spring-struts-forwardport,代碼行數:47,代碼來源:ContextLoaderPlugIn.java

示例6: registerSubContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
public void registerSubContext(String webAppKey) {
    // get the sub contexts - servlet context
    ServletContext ctx = servletContext.getContext(webAppKey);
    if (ctx == null) {
        ctx = servletContext;
    }
    ContextLoader loader = new ContextLoader();
    ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) loader.initWebApplicationContext(ctx);
    appCtx.setParent(applicationContext);
    appCtx.refresh();

    ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx);

    ConfigurableBeanFactory appFactory = appCtx.getBeanFactory();

    logger.debug("About to grab Webcontext bean for {}", webAppKey);
    Context webContext = (Context) appCtx.getBean("web.context");
    webContext.setCoreBeanFactory(parentFactory);
    webContext.setClientRegistry(clientRegistry);
    webContext.setServiceInvoker(globalInvoker);
    webContext.setScopeResolver(globalResolver);
    webContext.setMappingStrategy(globalStrategy);

    WebScope scope = (WebScope) appFactory.getBean("web.scope");
    scope.setServer(server);
    scope.setParent(global);
    scope.register();
    scope.start();

    // register the context so we dont try to reinitialize it
    registeredContexts.add(ctx);

}
 
開發者ID:Red5,項目名稱:red5-server,代碼行數:34,代碼來源:WarLoaderServlet.java

示例7: resolve

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
@Override
public void resolve(PluginContext pluginContext) {
	ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) pluginContext
			.getApplication().getApplicationContext();
	if (pluginContext.getApplication().getParent() != null) {
		applicationContext.setParent(pluginContext.getApplication().getParent().getApplicationContext());
		applicationContext.refresh();
	}
}
 
開發者ID:code4craft,項目名稱:tavern,代碼行數:10,代碼來源:SpringTavernPlugin.java

示例8: registerSubContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
public void registerSubContext(String webAppKey) {
	// get the sub contexts - servlet context
	ServletContext ctx = servletContext.getContext(webAppKey);
	if (ctx == null) {
		ctx = servletContext;
	}
	ContextLoader loader = new ContextLoader();
	ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) loader.initWebApplicationContext(ctx);
	appCtx.setParent(applicationContext);
	appCtx.refresh();

	ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx);

	ConfigurableBeanFactory appFactory = appCtx.getBeanFactory();

	logger.debug("About to grab Webcontext bean for {}", webAppKey);
	Context webContext = (Context) appCtx.getBean("web.context");
	webContext.setCoreBeanFactory(parentFactory);
	webContext.setClientRegistry(clientRegistry);
	webContext.setServiceInvoker(globalInvoker);
	webContext.setScopeResolver(globalResolver);
	webContext.setMappingStrategy(globalStrategy);

	WebScope scope = (WebScope) appFactory.getBean("web.scope");
	scope.setServer(server);
	scope.setParent(global);
	scope.register();
	scope.start();

	// register the context so we dont try to reinitialize it
	registeredContexts.add(ctx);

}
 
開發者ID:cwpenhale,項目名稱:red5-mobileconsole,代碼行數:34,代碼來源:WarLoaderServlet.java

示例9: initWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
/**
 * Initialize and publish the WebApplicationContext for this servlet.
 * <p>Delegates to {@link #createWebApplicationContext} for actual creation
 * of the context. Can be overridden in subclasses.
 * @return the WebApplicationContext instance
 * @see #FrameworkServlet(WebApplicationContext)
 * @see #setContextClass
 * @see #setContextConfigLocation
 */
protected WebApplicationContext initWebApplicationContext() {
	WebApplicationContext rootContext =
			WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	WebApplicationContext wac = null;

	if (this.webApplicationContext != null) {
		// A context instance was injected at construction time -> use it
		wac = this.webApplicationContext;
		if (wac instanceof ConfigurableWebApplicationContext) {
			ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) wac;
			if (!cwac.isActive()) {
				// The context has not yet been refreshed -> provide services such as
				// setting the parent context, setting the application context id, etc
				if (cwac.getParent() == null) {
					// The context instance was injected without an explicit parent -> set
					// the root application context (if any; may be null) as the parent
					cwac.setParent(rootContext);
				}
				configureAndRefreshWebApplicationContext(cwac);
			}
		}
	}
	if (wac == null) {
		// No context instance was injected at construction time -> see if one
		// has been registered in the servlet context. If one exists, it is assumed
		// that the parent context (if any) has already been set and that the
		// user has performed any initialization such as setting the context id
		wac = findWebApplicationContext();
	}
	if (wac == null) {
		// No context instance is defined for this servlet -> create a local one
		wac = createWebApplicationContext(rootContext);
	}

	if (!this.refreshEventReceived) {
		// Either the context is not a ConfigurableApplicationContext with refresh
		// support or the context injected at construction time had already been
		// refreshed -> trigger initial onRefresh manually here.
		onRefresh(wac);
	}

	if (this.publishContext) {
		// Publish the context as a servlet context attribute.
		String attrName = getServletContextAttributeName();
		getServletContext().setAttribute(attrName, wac);
		if (this.logger.isDebugEnabled()) {
			this.logger.debug("Published WebApplicationContext of servlet '" + getServletName() +
					"' as ServletContext attribute with name [" + attrName + "]");
		}
	}

	return wac;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:63,代碼來源:FrameworkServlet.java


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