本文整理汇总了Java中org.springframework.web.context.ConfigurableWebApplicationContext.refresh方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableWebApplicationContext.refresh方法的具体用法?Java ConfigurableWebApplicationContext.refresh怎么用?Java ConfigurableWebApplicationContext.refresh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.ConfigurableWebApplicationContext
的用法示例。
在下文中一共展示了ConfigurableWebApplicationContext.refresh方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureAndRefreshWebApplicationContext
import org.springframework.web.context.ConfigurableWebApplicationContext; //导入方法依赖的package包/类
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) {
if (ObjectUtils.identityToString(wac).equals(wac.getId())) {
// The application context id is still set to its original default value
// -> assign a more useful id based on available information
if (this.contextId != null) {
wac.setId(this.contextId);
}
else {
// Generate default id...
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
ObjectUtils.getDisplayString(getServletContext().getContextPath()) + "/" + getServletName());
}
}
wac.setServletContext(getServletContext());
wac.setServletConfig(getServletConfig());
wac.setNamespace(getNamespace());
wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));
// The wac environment's #initPropertySources will be called in any case when the context
// is refreshed; do it eagerly here to ensure servlet property sources are in place for
// use in any post-processing or initialization that occurs below prior to #refresh
ConfigurableEnvironment env = wac.getEnvironment();
if (env instanceof ConfigurableWebEnvironment) {
((ConfigurableWebEnvironment) env).initPropertySources(getServletContext(), getServletConfig());
}
postProcessWebApplicationContext(wac);
applyInitializers(wac);
wac.refresh();
}
示例2: 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;
}
示例3: 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);
}
示例4: 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();
}
}
示例5: 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);
}
示例6: configureAndRefreshWebApplicationContext
import org.springframework.web.context.ConfigurableWebApplicationContext; //导入方法依赖的package包/类
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) {
if (ObjectUtils.identityToString(wac).equals(wac.getId())) {
// The application context id is still set to its original default value
// -> assign a more useful id based on available information
if (this.contextId != null) {
wac.setId(this.contextId);
}
else {
// Generate default id...
ServletContext sc = getServletContext();
if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
// Servlet <= 2.4: resort to name specified in web.xml, if any.
String servletContextName = sc.getServletContextName();
if (servletContextName != null) {
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + servletContextName +
"." + getServletName());
}
else {
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + getServletName());
}
}
else {
// Servlet 2.5's getContextPath available!
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
ObjectUtils.getDisplayString(sc.getContextPath()) + "/" + getServletName());
}
}
}
wac.setServletContext(getServletContext());
wac.setServletConfig(getServletConfig());
wac.setNamespace(getNamespace());
wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));
// The wac environment's #initPropertySources will be called in any case when the context
// is refreshed; do it eagerly here to ensure servlet property sources are in place for
// use in any post-processing or initialization that occurs below prior to #refresh
ConfigurableEnvironment env = wac.getEnvironment();
if (env instanceof ConfigurableWebEnvironment) {
((ConfigurableWebEnvironment) env).initPropertySources(getServletContext(), getServletConfig());
}
postProcessWebApplicationContext(wac);
applyInitializers(wac);
wac.refresh();
}
示例7: contextInitialized
import org.springframework.web.context.ConfigurableWebApplicationContext; //导入方法依赖的package包/类
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION")
public void contextInitialized(ServletContextEvent servletContextEvent) {
ServletContext servletContext = servletContextEvent.getServletContext();
StringBuilder configLocation = new StringBuilder();
configLocation.append("classpath:org/geomajas/spring/geomajasContext.xml");
String additionalLocations = servletContext.getInitParameter(CONFIG_LOCATION_PARAMETER);
if (null != additionalLocations) {
for (String onePart : additionalLocations.split("\\s")) {
String part = onePart.trim();
if (part.length() > 0) {
configLocation.append(',');
int pos = part.indexOf(':');
if (pos < 0) {
// no protocol specified, use classpath.
configLocation.append(GeomajasConstant.CLASSPATH_URL_PREFIX);
} else if (0 == pos) {
// location starts with colon, use default application context
part = part.substring(1);
}
configLocation.append(part);
}
}
}
ConfigurableWebApplicationContext applicationContext = new XmlWebApplicationContext();
// Assign the best possible id value.
String id;
try {
String contextPath = (String) ServletContext.class.getMethod("getContextPath").invoke(servletContext);
id = ObjectUtils.getDisplayString(contextPath);
} catch (Exception ex) {
// Servlet <= 2.4: resort to name specified in web.xml, if any.
String servletContextName = servletContext.getServletContextName();
id = ObjectUtils.getDisplayString(servletContextName);
}
applicationContext.setId("Geomajas:" + id);
applicationContext.setServletContext(servletContext);
applicationContext.setConfigLocation(configLocation.toString());
applicationContext.refresh();
ApplicationContextUtil.setApplicationContext(servletContext, applicationContext);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
}