本文整理汇总了Java中org.springframework.web.context.ContextLoader.initWebApplicationContext方法的典型用法代码示例。如果您正苦于以下问题:Java ContextLoader.initWebApplicationContext方法的具体用法?Java ContextLoader.initWebApplicationContext怎么用?Java ContextLoader.initWebApplicationContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.ContextLoader
的用法示例。
在下文中一共展示了ContextLoader.initWebApplicationContext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateTargetUrlWithContextLoader
import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
@Test
public void updateTargetUrlWithContextLoader() throws Exception {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
MockServletContext servletContext = new MockServletContext();
ContextLoader contextLoader = new ContextLoader(wac);
contextLoader.initWebApplicationContext(servletContext);
try {
RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
RedirectView rv = new RedirectView();
rv.setUrl("/path");
MockHttpServletRequest request = createRequest();
HttpServletResponse response = new MockHttpServletResponse();
given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
rv.render(new ModelMap(), request, response);
verify(mockProcessor).processUrl(request, "/path");
}
finally {
contextLoader.closeWebApplicationContext(servletContext);
}
}
示例2: init
import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
@BeforeClass
public static void init() {
mockServletContext = new MockServletContext();
String configLocations = "classpath:TagSpringBeans.xml";
mockServletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, configLocations);
ContextLoader loader = new ContextLoader();
loader.initWebApplicationContext(mockServletContext);
}
示例3: init
import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
@BeforeClass
public static void init() {
mockServletContext = new MockServletContext();
String configLocations = "classpath:TagSpringBeans.xml";
mockServletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, configLocations);
ContextLoader loader = new ContextLoader();
loader.initWebApplicationContext(mockServletContext);
nci.setKmeProperties(new Properties());
}
示例4: init
import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
@BeforeClass
public static void init() {
mockServletContext = new MockServletContext();
String configLocations = "classpath:ThemeTestSpringBeans.xml";
mockServletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, configLocations);
ContextLoader loader = new ContextLoader();
loader.initWebApplicationContext(mockServletContext);
}
示例5: registerSubContext
import org.springframework.web.context.ContextLoader; //导入方法依赖的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: registerSubContext
import org.springframework.web.context.ContextLoader; //导入方法依赖的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);
}