本文整理汇总了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());
}
示例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);
}
示例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);
}
示例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();
}
示例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());
}