use of org.springframework.web.context.ConfigurableWebApplicationContext in project spring-framework by spring-projects.
the class FrameworkServlet method initWebApplicationContext.
/**
* 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()) {
// 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;
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project cuba by cuba-platform.
the class SingleAppRestApiServlet method createWebApplicationContext.
@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;
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project cuba by cuba-platform.
the class SingleAppIdpServlet method createWebApplicationContext.
@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;
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project pentaho-platform by pentaho.
the class PentahoWSSpringServlet method getAppContext.
protected ApplicationContext getAppContext() {
ConfigurableWebApplicationContext wac = new XmlWebApplicationContext() {
@Override
protected Resource getResourceByPath(String path) {
return new FileSystemResource(new File(path));
}
};
wac.setServletContext(getServletContext());
wac.setServletConfig(getServletConfig());
wac.setNamespace(getServletName());
String springFile = PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$ //$NON-NLS-2$
"system" + File.separator + "pentahoServices.spring.xml");
wac.setConfigLocations(new String[] { springFile });
wac.refresh();
return wac;
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project pentaho-platform by pentaho.
the class GwtRpcProxyServlet method getAppContext.
protected ApplicationContext getAppContext() {
WebApplicationContext parent = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
ConfigurableWebApplicationContext wac = new XmlWebApplicationContext() {
@Override
protected Resource getResourceByPath(String path) {
return new FileSystemResource(new File(path));
}
};
wac.setParent(parent);
wac.setServletContext(getServletContext());
wac.setServletConfig(getServletConfig());
wac.setNamespace(getServletName());
String springFile = PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$ //$NON-NLS-2$
"system" + File.separator + "pentahoServices.spring.xml");
wac.setConfigLocations(new String[] { springFile });
wac.refresh();
return wac;
}
Aggregations