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


Java GenericWebApplicationContext.getBean方法代码示例

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


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

示例1: configureExporterParametersWithEncodingFromPropertiesFile

import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void configureExporterParametersWithEncodingFromPropertiesFile() throws Exception {
	GenericWebApplicationContext ac = new GenericWebApplicationContext();
	ac.setServletContext(new MockServletContext());
	BeanDefinitionReader reader = new PropertiesBeanDefinitionReader(ac);
	reader.loadBeanDefinitions(new ClassPathResource("view.properties", getClass()));
	ac.refresh();

	AbstractJasperReportsView view = (AbstractJasperReportsView) ac.getBean("report");
	String encoding = (String) view.getConvertedExporterParameters().get(
		net.sf.jasperreports.engine.export.JRHtmlExporterParameter.CHARACTER_ENCODING);
	assertEquals("UTF-8", encoding);

	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);
	view.render(getModel(), request, response);
	assertEquals("Response content type is incorrect", "text/html;charset=UTF-8", response.getContentType());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:JasperReportsHtmlViewTests.java

示例2: HandlerMethodAnnotationDetectionTests

import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
public HandlerMethodAnnotationDetectionTests(final Class<?> controllerType, boolean useAutoProxy) {
	GenericWebApplicationContext context = new GenericWebApplicationContext();
	context.registerBeanDefinition("controller", new RootBeanDefinition(controllerType));
	context.registerBeanDefinition("handlerMapping", new RootBeanDefinition(RequestMappingHandlerMapping.class));
	context.registerBeanDefinition("handlerAdapter", new RootBeanDefinition(RequestMappingHandlerAdapter.class));
	context.registerBeanDefinition("exceptionResolver", new RootBeanDefinition(ExceptionHandlerExceptionResolver.class));
	if (useAutoProxy) {
		DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
		autoProxyCreator.setBeanFactory(context.getBeanFactory());
		context.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
		context.registerBeanDefinition("controllerAdvice", new RootBeanDefinition(ControllerAdvisor.class));
	}
	context.refresh();

	this.handlerMapping = context.getBean(RequestMappingHandlerMapping.class);
	this.handlerAdapter = context.getBean(RequestMappingHandlerAdapter.class);
	this.exceptionResolver = context.getBean(ExceptionHandlerExceptionResolver.class);
	context.close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:HandlerMethodAnnotationDetectionTests.java


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