本文整理汇总了Java中org.springframework.web.context.support.XmlWebApplicationContext类的典型用法代码示例。如果您正苦于以下问题:Java XmlWebApplicationContext类的具体用法?Java XmlWebApplicationContext怎么用?Java XmlWebApplicationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XmlWebApplicationContext类属于org.springframework.web.context.support包,在下文中一共展示了XmlWebApplicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.springframework.web.context.support.XmlWebApplicationContext; //导入依赖的package包/类
@Before
public void setUp() {
applicationContext = new XmlWebApplicationContext();
applicationContext.setConfigLocations(
"file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
"file:src/main/webapp/WEB-INF/managementConfigContext.xml",
"file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
return new FileSystemResource("src/main/webapp" + location);
}
@Override
public ClassLoader getClassLoader() {
return getClassLoader();
}
}));
applicationContext.refresh();
}
示例2: handleRequest
import org.springframework.web.context.support.XmlWebApplicationContext; //导入依赖的package包/类
public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context)
{
if (!isinitialized) {
isinitialized = true;
try {
XmlWebApplicationContext wc = new XmlWebApplicationContext();
wc.setConfigLocation("classpath:/staticAppContext.xml");
handler = SpringLambdaContainerHandler.getAwsProxyHandler(wc);
} catch (ContainerInitializationException e) {
e.printStackTrace();
return null;
}
}
AwsProxyResponse res = handler.proxy(awsProxyRequest, context);
return res;
}
示例3: setUp
import org.springframework.web.context.support.XmlWebApplicationContext; //导入依赖的package包/类
@Before
public void setUp() {
applicationContext = new XmlWebApplicationContext();
applicationContext.setConfigLocations(
"classpath:/webappContext.xml",
"file:src/main/webapp/WEB-INF/cas-servlet.xml",
"file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
"file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
return new FileSystemResource("src/main/webapp" + location);
}
@Override
public ClassLoader getClassLoader() {
return getClassLoader();
}
}));
applicationContext.refresh();
}
示例4: setUp
import org.springframework.web.context.support.XmlWebApplicationContext; //导入依赖的package包/类
@Before
public void setUp() {
applicationContext = new XmlWebApplicationContext();
applicationContext.setConfigLocations(
"classpath:/cas-management-servlet.xml",
"classpath:/managementConfigContext.xml",
"classpath:/spring-configuration/*.xml");
applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
return new FileSystemResource("src/main/webapp" + location);
}
@Override
public ClassLoader getClassLoader() {
return WiringTests.class.getClassLoader();
}
}));
applicationContext.refresh();
}
示例5: setUp
import org.springframework.web.context.support.XmlWebApplicationContext; //导入依赖的package包/类
@Before
public void setUp() {
applicationContext = new XmlWebApplicationContext();
applicationContext.setConfigLocations(
"file:src/main/webapp/WEB-INF/cas-servlet.xml",
"file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
"file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
return new FileSystemResource("src/main/webapp" + location);
}
@Override
public ClassLoader getClassLoader() {
return getClassLoader();
}
}));
applicationContext.refresh();
}
示例6: setUp
import org.springframework.web.context.support.XmlWebApplicationContext; //导入依赖的package包/类
@Before
public void setUp() {
applicationContext = new XmlWebApplicationContext();
applicationContext.setConfigLocations(new String[]{
"file:src/main/webapp/WEB-INF/cas-servlet.xml",
"file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
"file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
return new FileSystemResource("src/main/webapp" + location);
}
@Override
public ClassLoader getClassLoader() {
return getClassLoader();
}
}));
applicationContext.refresh();
}
示例7: setUp
import org.springframework.web.context.support.XmlWebApplicationContext; //导入依赖的package包/类
@Before
public void setUp() {
applicationContext = new XmlWebApplicationContext();
applicationContext.setConfigLocations(new String[]{
"file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
"file:src/main/webapp/WEB-INF/managementConfigContext.xml",
"file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
return new FileSystemResource("src/main/webapp" + location);
}
@Override
public ClassLoader getClassLoader() {
return getClassLoader();
}
}));
applicationContext.refresh();
}
示例8: 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());
}
}
示例9: 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));
}
示例10: testContextLoaderListenerWithDefaultContext
import org.springframework.web.context.support.XmlWebApplicationContext; //导入依赖的package包/类
@Test
public void testContextLoaderListenerWithDefaultContext() {
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
"/org/springframework/web/context/WEB-INF/applicationContext.xml " +
"/org/springframework/web/context/WEB-INF/context-addition.xml");
ServletContextListener listener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc);
listener.contextInitialized(event);
WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
assertTrue("Correct WebApplicationContext exposed in ServletContext", context instanceof XmlWebApplicationContext);
assertTrue(WebApplicationContextUtils.getRequiredWebApplicationContext(sc) instanceof XmlWebApplicationContext);
LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle");
assertTrue("Has father", context.containsBean("father"));
assertTrue("Has rod", context.containsBean("rod"));
assertTrue("Has kerry", context.containsBean("kerry"));
assertTrue("Not destroyed", !lb.isDestroyed());
assertFalse(context.containsBean("beans1.bean1"));
assertFalse(context.containsBean("beans1.bean2"));
listener.contextDestroyed(event);
assertTrue("Destroyed", lb.isDestroyed());
assertNull(sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
assertNull(WebApplicationContextUtils.getWebApplicationContext(sc));
}
示例11: initialize
import org.springframework.web.context.support.XmlWebApplicationContext; //导入依赖的package包/类
@Override
public void initialize( XmlWebApplicationContext applicationContext )
{
ConfigurableEnvironment env = applicationContext.getEnvironment();
WorkDir workDir;
try
{
workDir = new WorkDir( applicationContext.getServletContext() );
}
catch ( IOException e )
{
throw new ApplicationContextException( "Error obtaining QuartzDesk Executor work directory.", e );
}
String databaseProfile = getDatabaseProfile( workDir );
String[] activeProfiles = new String[] { databaseProfile };
log.info( "Activating Spring profiles: {}", Arrays.toString( activeProfiles ) );
env.setActiveProfiles( activeProfiles );
}
示例12: initDispatcherServlet
import org.springframework.web.context.support.XmlWebApplicationContext; //导入依赖的package包/类
/**
* <p>默认关闭<p>
* 加载spring mvc 统一调度器
* @param servletContext
*/
protected void initDispatcherServlet(ServletContext servletContext){
String enable = servletContext.getInitParameter("enableDispatcherServlet");
if(BooleanUtils.valueOf(enable)){
//classpath*:/spring-mvc*.xml,/WEB-INF/spring-mvc*.xml
XmlWebApplicationContext appContext = new XmlWebApplicationContext();
appContext.setConfigLocation("classpath*:/spring/spring-mvc*.xml,/WEB-INF/spring/spring-mvc*.xml");
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(appContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
示例13: 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;
}
示例14: 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();
}
}
示例15: onSubmit
import org.springframework.web.context.support.XmlWebApplicationContext; //导入依赖的package包/类
@Override
protected void onSubmit() {
try {
ConnectionPropertiesPatcher.patch(getModelObject());
XmlWebApplicationContext ctx = (XmlWebApplicationContext)getWebApplicationContext(Application.get().getServletContext());
if (ctx == null) {
form.error(new StringResourceModel("install.wizard.db.step.error.patch", InstallWizard.this).setParameters("Web context is NULL").getObject());
log.error("Web context is NULL");
return;
}
LocalEntityManagerFactoryBean emb = ctx.getBeanFactory().getBean(LocalEntityManagerFactoryBean.class);
emb.afterPropertiesSet();
dbType = getModelObject().getDbType();
} catch (Exception e) {
form.error(new StringResourceModel("install.wizard.db.step.error.patch", InstallWizard.this).setParameters(e.getMessage()).getObject());
log.error("error while patching", e);
}
}