本文整理汇总了Java中org.springframework.web.context.support.XmlWebApplicationContext.setParent方法的典型用法代码示例。如果您正苦于以下问题:Java XmlWebApplicationContext.setParent方法的具体用法?Java XmlWebApplicationContext.setParent怎么用?Java XmlWebApplicationContext.setParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.support.XmlWebApplicationContext
的用法示例。
在下文中一共展示了XmlWebApplicationContext.setParent方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handlerBeanNotFound
import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
@Test
public void handlerBeanNotFound() throws Exception {
MockServletContext sc = new MockServletContext("");
XmlWebApplicationContext root = new XmlWebApplicationContext();
root.setServletContext(sc);
root.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map1.xml"});
root.refresh();
XmlWebApplicationContext wac = new XmlWebApplicationContext();
wac.setParent(root);
wac.setServletContext(sc);
wac.setNamespace("map2err");
wac.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map2err.xml"});
try {
wac.refresh();
fail("Should have thrown NoSuchBeanDefinitionException");
}
catch (FatalBeanException ex) {
NoSuchBeanDefinitionException nestedEx = (NoSuchBeanDefinitionException) ex.getCause();
assertEquals("mainControlle", nestedEx.getBeanName());
}
}
示例2: withoutMessageSource
import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("resource")
public void withoutMessageSource() throws Exception {
MockServletContext sc = new MockServletContext("");
XmlWebApplicationContext wac = new XmlWebApplicationContext();
wac.setParent(root);
wac.setServletContext(sc);
wac.setNamespace("testNamespace");
wac.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/test-servlet.xml"});
wac.refresh();
try {
wac.getMessage("someMessage", null, Locale.getDefault());
fail("Should have thrown NoSuchMessageException");
}
catch (NoSuchMessageException ex) {
// expected;
}
String msg = wac.getMessage("someMessage", null, "default", Locale.getDefault());
assertTrue("Default message returned", "default".equals(msg));
}
示例3: createMainDispatcherServlet
import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
private void createMainDispatcherServlet(ApplicationContext rootContext) {
mainWebApplicationContext = new XmlWebApplicationContext();
mainWebApplicationContext
.setConfigLocation(getRequiredInitParameter("communoteWebContextConfigLocation"));
mainWebApplicationContext.setParent(rootContext);
// add ContextLoaderListener with web-ApplicationContext which publishes it under a
// ServletContext attribute and closes it on shutdown. The former is required for
// WebApplicationContextUtils which are used by DelegatingFilterProxy (spring security).
// Closing is also done by dispatcher servlet's implementation of destroy method.
this.servletContext.addListener(new ContextLoaderListener(mainWebApplicationContext));
DispatcherServlet dispatcherServlet = new DispatcherServlet(mainWebApplicationContext);
ServletRegistration.Dynamic addedServlet = this.servletContext.addServlet(
getInitParameter("communoteServletName", "communote"), dispatcherServlet);
addedServlet.setLoadOnStartup(1);
addedServlet.addMapping(getRequiredInitParameter("communoteServletUrlPattern"));
this.mainDispatcherServlet = dispatcherServlet;
}
示例4: start
import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
if(!isStarted()){
LOG.info("Creating Spring context " + StringUtils.join(this.fileLocs, ","));
if (parentSpringResourceLoader != null && parentContext != null) {
throw new ConfigurationException("Both a parentSpringResourceLoader and parentContext were defined. Only one can be defined!");
}
if (parentSpringResourceLoader != null) {
parentContext = parentSpringResourceLoader.getContext();
}
if (servletContextcontext != null) {
XmlWebApplicationContext lContext = new XmlWebApplicationContext();
lContext.setServletContext(servletContextcontext);
lContext.setParent(parentContext);
lContext.setConfigLocations(this.fileLocs.toArray(new String[] {}));
lContext.refresh();
context = lContext;
} else {
this.context = new ClassPathXmlApplicationContext(this.fileLocs.toArray(new String[] {}), parentContext);
}
super.start();
}
}
示例5: testWithoutMessageSource
import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
public void testWithoutMessageSource() throws Exception {
MockServletContext sc = new MockServletContext("");
XmlWebApplicationContext wac = new XmlWebApplicationContext();
wac.setParent(root);
wac.setServletContext(sc);
wac.setNamespace("testNamespace");
wac.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/test-servlet.xml"});
wac.refresh();
try {
wac.getMessage("someMessage", null, Locale.getDefault());
fail("Should have thrown NoSuchMessageException");
}
catch (NoSuchMessageException ex) {
// expected;
}
String msg = wac.getMessage("someMessage", null, "default", Locale.getDefault());
assertTrue("Default message returned", "default".equals(msg));
}
示例6: onStartup
import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
public void onStartup(ServletContext container) {
XmlWebApplicationContext appContext = new XmlWebApplicationContext();
appContext.setBeanName("fakeEmptyContext");
String fakeEmptyContext = SpringUtils.fakeEmptyContext();
appContext.setParent(springCtxInWhichJettyRuns);
appContext.setConfigLocation(fakeEmptyContext);
appContext.refresh();
DispatcherServlet dispatcherServlet = new DispatcherServlet(appContext);
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", dispatcherServlet);
dispatcher.setLoadOnStartup(1);
String[] dispatcherServletSubPath2 = SpringDispatcherServletFeature.this.dispatcherServletSubPath;
if(!ArrayUtils.isEmpty(dispatcherServletSubPath2)){
for (String string : dispatcherServletSubPath2) {
Set<String> alreadyExitingMappings = dispatcher.addMapping(string);
if(CollectionUtils.isNotEmpty(alreadyExitingMappings)){
throw new IllegalStateException(format("Mappings '%s' was already assigned to another servlet.", alreadyExitingMappings));
}
}
}
}
示例7: createServletApplicationContext
import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
@Override
protected WebApplicationContext createServletApplicationContext() {
XmlWebApplicationContext wac = new XmlWebApplicationContext();
if(springCtxInWhichJettyRuns == null){
throw new IllegalStateException("Still null");
}
wac.setParent(springCtxInWhichJettyRuns);
return wac;
}
示例8: setParentContext
import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
/**
* Sets a parent context for child context based on a given key.
*
* @param parentContextKey
* key for the parent context
* @param appContextId
* id of the child context
*/
public void setParentContext(String parentContextKey, String appContextId) {
log.debug("Set parent context {} on {}", parentContextKey, appContextId);
ApplicationContext parentContext = getContext(parentContextKey);
if (parentContext != null) {
XmlWebApplicationContext childContext = (XmlWebApplicationContext) getContext(appContextId);
if (childContext != null) {
childContext.setParent(parentContext);
} else {
log.debug("Child context not found");
}
} else {
log.debug("Parent context not found");
}
}
示例9: initialize
import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
@Override
public void initialize(XmlWebApplicationContext ctx) {
ctx.setAllowBeanDefinitionOverriding(true);
ConfigurableEnvironment env = ctx.getEnvironment();
Set<String> aps = new LinkedHashSet<>();
Collections.addAll(aps, env.getActiveProfiles());
if (page != null) {
page.setAttribute(AppContextFinder.APP_CONTEXT_ATTRIB, ctx);
ServletContext sc = ExecutionContext.getSession().getServletContext();
ctx.setDisplayName("Child XmlWebApplicationContext " + page);
ctx.setParent(AppContextFinder.rootContext);
ctx.setServletContext(sc);
// Set up profiles (remove root profiles merged from parent)
aps.removeAll(Arrays.asList(Constants.PROFILES_ROOT));
Collections.addAll(aps, testConfig ? Constants.PROFILES_CHILD_TEST : Constants.PROFILES_CHILD_PROD);
env.setDefaultProfiles(Constants.PROFILE_CHILD_DEFAULT);
ctx.setConfigLocations(DEFAULT_LOCATIONS);
} else {
AppContextFinder.rootContext = ctx;
Collections.addAll(aps, testConfig ? Constants.PROFILES_ROOT_TEST : Constants.PROFILES_ROOT_PROD);
env.getPropertySources().addFirst(new LabelPropertySource());
env.getPropertySources().addLast(new DomainPropertySource(ctx));
env.setDefaultProfiles(Constants.PROFILE_ROOT_DEFAULT);
ctx.setConfigLocations((String[]) ArrayUtils.addAll(Constants.DEFAULT_LOCATIONS, ctx.getConfigLocations()));
ClasspathMessageSource.getInstance().setResourceLoader(ctx);
registerSessionListener();
}
env.setActiveProfiles(aps.toArray(new String[aps.size()]));
}
示例10: setParentContext
import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
/**
* Sets a parent context for child context based on a given key.
*
* @param parentContextKey key for the parent context
* @param appContextId id of the child context
*/
public void setParentContext(String parentContextKey, String appContextId) {
log.debug("Set parent context {} on {}", parentContextKey, appContextId);
ApplicationContext parentContext = getContext(parentContextKey);
if (parentContext != null) {
XmlWebApplicationContext childContext = (XmlWebApplicationContext) getContext(appContextId);
if (childContext != null) {
childContext.setParent(parentContext);
} else {
log.debug("Child context not found");
}
} else {
log.debug("Parent context not found");
}
}
示例11: refreshServletApplicationContext
import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
public void refreshServletApplicationContext() {
PluginManager pluginManager = WebPluginManagerUtils
.getPluginManager(this.getServletContext());
String[] contextPaths;
List<String> ctxPaths = new ArrayList<String>();
if (pluginManager != null) {
try {
// 获得扩展点
ExtensionPoint applicationExtPoint = pluginManager
.getRegistry().getExtensionPoint(PLUGIN_ID,
WEB_CONTEXT_EXTENSION_POINT);
for (Iterator<Extension> it = applicationExtPoint
.getConnectedExtensions().iterator(); it.hasNext();) {
Extension ext = it.next();
//
Parameter param = ext.getParameter("path");
//
String path = param.valueAsString();
String[] paths = path.split(",");
for (int j = 0; j < paths.length; j++) {
ctxPaths.add(paths[j]);
}
}
contextPaths = new String[ctxPaths.size()];
contextPaths = ctxPaths.toArray(new String[ctxPaths.size()]);
//
WebApplicationContext applicationContext = this
.getApplicationContext();
if (applicationContext == null) {
applicationContext = this.servletParentContext;
}
PluginClassLoader pcl = getManager().getPluginClassLoader(
getDescriptor());
servletAplicationContext = new XmlWebApplicationContext();
servletAplicationContext.setServletContext(this
.getServletContext());
if (applicationContext != null)
servletAplicationContext.setParent(applicationContext);
if (pcl != null)
servletAplicationContext.setClassLoader(pcl);
//
servletAplicationContext.setConfigLocations(contextPaths);
servletAplicationContext.refresh();
// this.getServletContext().setAttribute(this.getPluginId(),
// servletAplicationContext);
} catch (Exception ex1) {
this.log.error(ex1);
ex1.printStackTrace();
}
}
}