本文整理汇总了Java中org.springframework.web.context.support.GenericWebApplicationContext.setParent方法的典型用法代码示例。如果您正苦于以下问题:Java GenericWebApplicationContext.setParent方法的具体用法?Java GenericWebApplicationContext.setParent怎么用?Java GenericWebApplicationContext.setParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.support.GenericWebApplicationContext
的用法示例。
在下文中一共展示了GenericWebApplicationContext.setParent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
/**
* Sets up and runs server.
* @param args
*/
public static void main(String[] args)
{
final Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(8080);
server.addConnector(connector);
Context htmlContext = new Context(server, "/", Context.SESSIONS);
ResourceHandler htmlHandler = new ResourceHandler();
htmlHandler.setResourceBase("web");
htmlContext.setHandler(htmlHandler);
Context servletContext = new Context(server, "/", Context.SESSIONS);
GenericWebApplicationContext springContext = new GenericWebApplicationContext();
springContext.setParent(new ClassPathXmlApplicationContext("org/getahead/dwrdemo/cli/spring.xml"));
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, springContext);
ServletHolder holder = new ServletHolder(new DwrSpringServlet());
holder.setInitParameter("pollAndCometEnabled", "true");
holder.setInitParameter("debug", "true");
servletContext.addServlet(holder, "/dwr/*");
try
{
JettyShutdown.addShutdownHook(server);
server.start();
server.join();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
示例2: createWebApplicationContext
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
protected WebApplicationContext createWebApplicationContext(ServletContext sc, ApplicationContext parent)
{
GenericWebApplicationContext wac = (GenericWebApplicationContext) BeanUtils.instantiateClass(GenericWebApplicationContext.class);
// Assign the best possible id value.
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + contextPath);
wac.setParent(parent);
wac.setServletContext(sc);
wac.refresh();
return wac;
}
示例3: initFactory
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
/**
* Initialize the view bean factory from the XML file.
* Synchronized because of access by parallel threads.
* @throws BeansException in case of initialization errors
*/
protected synchronized BeanFactory initFactory() throws BeansException {
if (this.cachedFactory != null) {
return this.cachedFactory;
}
Resource actualLocation = this.location;
if (actualLocation == null) {
actualLocation = getApplicationContext().getResource(DEFAULT_LOCATION);
}
// Create child ApplicationContext for views.
GenericWebApplicationContext factory = new GenericWebApplicationContext();
factory.setParent(getApplicationContext());
factory.setServletContext(getServletContext());
// Load XML resource with context-aware entity resolver.
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
reader.setEnvironment(getApplicationContext().getEnvironment());
reader.setEntityResolver(new ResourceEntityResolver(getApplicationContext()));
reader.loadBeanDefinitions(actualLocation);
factory.refresh();
if (isCache()) {
this.cachedFactory = factory;
}
return factory;
}
示例4: loadContext
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
/**
* Load a Spring {@link WebApplicationContext} from the supplied
* {@link MergedContextConfiguration}.
*
* <p>Implementation details:
*
* <ul>
* <li>Calls {@link #validateMergedContextConfiguration(WebMergedContextConfiguration)}
* to allow subclasses to validate the supplied configuration before proceeding.</li>
* <li>Creates a {@link GenericWebApplicationContext} instance.</li>
* <li>If the supplied {@code MergedContextConfiguration} references a
* {@linkplain MergedContextConfiguration#getParent() parent configuration},
* the corresponding {@link MergedContextConfiguration#getParentApplicationContext()
* ApplicationContext} will be retrieved and
* {@linkplain GenericWebApplicationContext#setParent(ApplicationContext) set as the parent}
* for the context created by this method.</li>
* <li>Delegates to {@link #configureWebResources} to create the
* {@link MockServletContext} and set it in the {@code WebApplicationContext}.</li>
* <li>Calls {@link #prepareContext} to allow for customizing the context
* before bean definitions are loaded.</li>
* <li>Calls {@link #customizeBeanFactory} to allow for customizing the
* context's {@code DefaultListableBeanFactory}.</li>
* <li>Delegates to {@link #loadBeanDefinitions} to populate the context
* from the locations or classes in the supplied {@code MergedContextConfiguration}.</li>
* <li>Delegates to {@link AnnotationConfigUtils} for
* {@linkplain AnnotationConfigUtils#registerAnnotationConfigProcessors registering}
* annotation configuration processors.</li>
* <li>Calls {@link #customizeContext} to allow for customizing the context
* before it is refreshed.</li>
* <li>{@link ConfigurableApplicationContext#refresh Refreshes} the
* context and registers a JVM shutdown hook for it.</li>
* </ul>
*
* @return a new web application context
* @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration)
* @see GenericWebApplicationContext
*/
@Override
public final ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
if (!(mergedConfig instanceof WebMergedContextConfiguration)) {
throw new IllegalArgumentException(String.format(
"Cannot load WebApplicationContext from non-web merged context configuration %s. "
+ "Consider annotating your test class with @WebAppConfiguration.", mergedConfig));
}
WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) mergedConfig;
if (logger.isDebugEnabled()) {
logger.debug(String.format("Loading WebApplicationContext for merged context configuration %s.",
webMergedConfig));
}
validateMergedContextConfiguration(webMergedConfig);
GenericWebApplicationContext context = new GenericWebApplicationContext();
ApplicationContext parent = mergedConfig.getParentApplicationContext();
if (parent != null) {
context.setParent(parent);
}
configureWebResources(context, webMergedConfig);
prepareContext(context, webMergedConfig);
customizeBeanFactory(context.getDefaultListableBeanFactory(), webMergedConfig);
loadBeanDefinitions(context, webMergedConfig);
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
customizeContext(context, webMergedConfig);
context.refresh();
context.registerShutdownHook();
return context;
}