当前位置: 首页>>代码示例>>Java>>正文


Java XmlWebApplicationContext.getBean方法代码示例

本文整理汇总了Java中org.springframework.web.context.support.XmlWebApplicationContext.getBean方法的典型用法代码示例。如果您正苦于以下问题:Java XmlWebApplicationContext.getBean方法的具体用法?Java XmlWebApplicationContext.getBean怎么用?Java XmlWebApplicationContext.getBean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.context.support.XmlWebApplicationContext的用法示例。


在下文中一共展示了XmlWebApplicationContext.getBean方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
	super.setUp();
	ServletContext servletContext = new MockServletContext(
			new FileSystemResourceLoader());
	requestService = new MockHttpServletRequest("PUT", "/service");
	applicationContext = new XmlWebApplicationContext();
	applicationContext.setServletContext(servletContext);
	applicationContext.setConfigLocations(new String[] {
			"src/main/webapp/WEB-INF/handler-servlet.xml",
			"src/main/webapp/WEB-INF/applicationContext.xml" });
	try{
	applicationContext.refresh();
	}
	catch (Throwable e){
		e.printStackTrace();
	}
	handler = (GWTHandler) applicationContext.getBean("urlMapping", GWTHandler.class);
}
 
开发者ID:ggeorgovassilis,项目名称:gwt-sl,代码行数:21,代码来源:HandlerTest.java

示例2: setUp

import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
@Override
@Before
public void setUp() throws Exception {

	requestPayload = readResource("request_add.txt");
	responsePayload = readResource("response_add.txt");
	MockServletContext servletContext = new MockServletContext(new ResourceLoaderSupport());
	MockServletConfig servletConfig = new MockServletConfig(servletContext);
	applicationContext = new XmlWebApplicationContext();
	applicationContext.setServletContext(servletContext);
	applicationContext.setServletConfig(servletConfig);
	applicationContext.setConfigLocations(new String[] { "src/main/webapp/WEB-INF/exporter-servlet.xml",
			"src/main/webapp/WEB-INF/applicationContext.xml" });
	applicationContext.refresh();
	handlerMapping = (SimpleUrlHandlerMapping) applicationContext
			.getBean("org.springframework.web.servlet.handler.SimpleUrlHandlerMapping");
}
 
开发者ID:ggeorgovassilis,项目名称:gwt-sl,代码行数:18,代码来源:TestRPCExporter.java

示例3: setUp

import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
	MockServletContext sc = new MockServletContext("");
	wac = new XmlWebApplicationContext();
	wac.setServletContext(sc);
	wac.setConfigLocations(new String[] {CONF});
	wac.refresh();
	hm = (HandlerMapping) wac.getBean("urlMapping");
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:PathMatchingUrlHandlerMappingTests.java

示例4: checkMappings

import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
private void checkMappings(String beanName) throws Exception {
	MockServletContext sc = new MockServletContext("");
	XmlWebApplicationContext wac = new XmlWebApplicationContext();
	wac.setServletContext(sc);
	wac.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map2.xml"});
	wac.refresh();
	Object bean = wac.getBean("mainController");
	Object otherBean = wac.getBean("otherController");
	Object defaultBean = wac.getBean("starController");
	HandlerMapping hm = (HandlerMapping) wac.getBean(beanName);

	MockHttpServletRequest req = new MockHttpServletRequest("GET", "/welcome.html");
	HandlerExecutionChain hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
	assertEquals("/welcome.html", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));

	req = new MockHttpServletRequest("GET", "/welcome.x");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == otherBean);
	assertEquals("welcome.x", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));

	req = new MockHttpServletRequest("GET", "/welcome/");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == otherBean);
	assertEquals("welcome", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));

	req = new MockHttpServletRequest("GET", "/");
	req.setServletPath("/welcome.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/welcome.html");
	req.setContextPath("/app");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/show.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/bookseats.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/original-welcome.html");
	req.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "/welcome.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/original-show.html");
	req.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "/show.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/original-bookseats.html");
	req.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "/bookseats.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
	assertEquals("/", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));

	req = new MockHttpServletRequest("GET", "/somePath");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == defaultBean);
	assertEquals("/somePath", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:70,代码来源:SimpleUrlHandlerMappingTests.java

示例5: checkMappings

import org.springframework.web.context.support.XmlWebApplicationContext; //导入方法依赖的package包/类
private void checkMappings(String beanName) throws Exception {
	MockServletContext sc = new MockServletContext("");
	XmlWebApplicationContext wac = new XmlWebApplicationContext();
	wac.setServletContext(sc);
	wac.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map2.xml"});
	wac.refresh();
	Object bean = wac.getBean("mainController");
	Object otherBean = wac.getBean("otherController");
	Object defaultBean = wac.getBean("starController");
	HandlerMapping hm = (HandlerMapping) wac.getBean(beanName);

	MockHttpServletRequest req = new MockHttpServletRequest("GET", "/welcome.html");
	HandlerExecutionChain hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
	assertEquals("/welcome.html", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));

	req = new MockHttpServletRequest("GET", "/welcome.x");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == otherBean);
	assertEquals("welcome.x", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));

	req = new MockHttpServletRequest("GET", "/");
	req.setServletPath("/welcome.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/welcome.html");
	req.setContextPath("/app");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/show.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/bookseats.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/original-welcome.html");
	req.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "/welcome.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/original-show.html");
	req.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "/show.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/original-bookseats.html");
	req.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "/bookseats.html");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

	req = new MockHttpServletRequest("GET", "/");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
	assertEquals("/", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));

	req = new MockHttpServletRequest("GET", "/somePath");
	hec = getHandler(hm, req);
	assertTrue("Handler is correct bean", hec != null && hec.getHandler() == defaultBean);
	assertEquals("/somePath", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:65,代码来源:SimpleUrlHandlerMappingTests.java


注:本文中的org.springframework.web.context.support.XmlWebApplicationContext.getBean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。