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


Java ExceptionHandlerExceptionResolver.setApplicationContext方法代码示例

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


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

示例1: addDefaultHandlerExceptionResolvers

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入方法依赖的package包/类
/**
 * A method available to subclasses for adding default {@link HandlerExceptionResolver}s.
 * <p>Adds the following exception resolvers:
 * <ul>
 * <li>{@link ExceptionHandlerExceptionResolver}
 * for handling exceptions through @{@link ExceptionHandler} methods.
 * <li>{@link ResponseStatusExceptionResolver}
 * for exceptions annotated with @{@link ResponseStatus}.
 * <li>{@link DefaultHandlerExceptionResolver}
 * for resolving known Spring exception types
 * </ul>
 */
protected final void addDefaultHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
	ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver = new ExceptionHandlerExceptionResolver();
	exceptionHandlerExceptionResolver.setContentNegotiationManager(mvcContentNegotiationManager());
	exceptionHandlerExceptionResolver.setMessageConverters(getMessageConverters());
	if (jackson2Present) {
		List<ResponseBodyAdvice<?>> interceptors = new ArrayList<ResponseBodyAdvice<?>>();
		interceptors.add(new JsonViewResponseBodyAdvice());
		exceptionHandlerExceptionResolver.setResponseBodyAdvice(interceptors);
	}
	exceptionHandlerExceptionResolver.setApplicationContext(this.applicationContext);
	exceptionHandlerExceptionResolver.afterPropertiesSet();
	exceptionResolvers.add(exceptionHandlerExceptionResolver);

	ResponseStatusExceptionResolver responseStatusExceptionResolver = new ResponseStatusExceptionResolver();
	responseStatusExceptionResolver.setMessageSource(this.applicationContext);
	exceptionResolvers.add(responseStatusExceptionResolver);

	exceptionResolvers.add(new DefaultHandlerExceptionResolver());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:32,代码来源:WebMvcConfigurationSupport.java

示例2: setup

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入方法依赖的package包/类
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);

    final ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver = new ExceptionHandlerExceptionResolver();
    final StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerBeanDefinition("advice", new RootBeanDefinition(GlobalErrorHandler.class, null, null));
    exceptionHandlerExceptionResolver.setApplicationContext(applicationContext);
    exceptionHandlerExceptionResolver.afterPropertiesSet();

    mockMvc = MockMvcBuilders.standaloneSetup(gatewayController).setHandlerExceptionResolvers(exceptionHandlerExceptionResolver).build();


    JSON_SMS json_sms = new JSON_SMS();
    json_sms.setMsisdn("34646974525");
    json_sms.setSender("sender");
    json_sms.setText("message test");
    requestJSON.addSMS(json_sms);
    requestJSON.addSMS(json_sms);
}
 
开发者ID:amalio,项目名称:spring-json-sms-gateway,代码行数:21,代码来源:GatewayControllerTests.java

示例3: setUp

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入方法依赖的package包/类
@Before
public void setUp() throws GeoLocationException {

	final ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver();
	final StaticApplicationContext applicationContext = new StaticApplicationContext();
	applicationContext.registerBeanDefinition("solrController",
			new RootBeanDefinition(SolrController.class, null, null));
	exceptionResolver.setApplicationContext(applicationContext);
	exceptionResolver.afterPropertiesSet();

	mockProductService = mock(ProductService.class);

	String badLocation = "35.453487-97.5184727";
	when(mockProductService.getProductsByLocation(badLocation)).thenThrow(new GeoLocationException());

	solrController = new SolrController(mockProductService);
	mockMvc = MockMvcBuilders.standaloneSetup(solrController)
			.setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver())
			.setHandlerExceptionResolvers(exceptionResolver).build();

	product = createProduct(1000);
	when(mockProductService.getProduct(PRODUCT_ID)).thenReturn(product);

	allProducts = createProductList(10);
	when(mockProductService.getProducts()).thenReturn(allProducts);

}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:28,代码来源:SolrProductControllerTests.java

示例4: configureCustomHandlerMethodArgumentResolver

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入方法依赖的package包/类
private void configureCustomHandlerMethodArgumentResolver(final ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver) {
    final List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();
    resolvers.addAll(exceptionHandlerExceptionResolver.getArgumentResolvers().getResolvers());
    resolvers.add(flashMessagesMethodArgumentResolver());

    exceptionHandlerExceptionResolver.setArgumentResolvers(resolvers);
    exceptionHandlerExceptionResolver.setApplicationContext(this.applicationContext);
    exceptionHandlerExceptionResolver.afterPropertiesSet();
}
 
开发者ID:jeslopalo,项目名称:flash-messages,代码行数:10,代码来源:FlashMessagesConfigurationSupport.java

示例5: addDefaultHandlerExceptionResolvers

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入方法依赖的package包/类
/**
 * A method available to subclasses for adding default {@link HandlerExceptionResolver}s.
 * <p>Adds the following exception resolvers:
 * <ul>
 * 	<li>{@link ExceptionHandlerExceptionResolver}
 * 	for handling exceptions through @{@link ExceptionHandler} methods.
 * 	<li>{@link ResponseStatusExceptionResolver}
 * 	for exceptions annotated with @{@link ResponseStatus}.
 * 	<li>{@link DefaultHandlerExceptionResolver}
 * 	for resolving known Spring exception types
 * </ul>
 */
protected final void addDefaultHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
	ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver = new ExceptionHandlerExceptionResolver();
	exceptionHandlerExceptionResolver.setApplicationContext(this.applicationContext);
	exceptionHandlerExceptionResolver.setContentNegotiationManager(mvcContentNegotiationManager());
	exceptionHandlerExceptionResolver.setMessageConverters(getMessageConverters());
	exceptionHandlerExceptionResolver.afterPropertiesSet();

	exceptionResolvers.add(exceptionHandlerExceptionResolver);
	exceptionResolvers.add(new ResponseStatusExceptionResolver());
	exceptionResolvers.add(new DefaultHandlerExceptionResolver());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:WebMvcConfigurationSupport.java


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