本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
}
示例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);
}
示例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;
}