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


Java ExceptionHandlerExceptionResolver类代码示例

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


ExceptionHandlerExceptionResolver类属于org.springframework.web.servlet.mvc.method.annotation包,在下文中一共展示了ExceptionHandlerExceptionResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: handlerExceptionResolver

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入依赖的package包/类
@Test
public void handlerExceptionResolver() throws Exception {

	delegatingConfig.setConfigurers(Arrays.asList(webMvcConfigurer));
	delegatingConfig.handlerExceptionResolver();

	verify(webMvcConfigurer).configureMessageConverters(converters.capture());
	verify(webMvcConfigurer).configureContentNegotiation(contentNegotiationConfigurer.capture());
	verify(webMvcConfigurer).configureHandlerExceptionResolvers(exceptionResolvers.capture());

	assertEquals(3, exceptionResolvers.getValue().size());
	assertTrue(exceptionResolvers.getValue().get(0) instanceof ExceptionHandlerExceptionResolver);
	assertTrue(exceptionResolvers.getValue().get(1) instanceof ResponseStatusExceptionResolver);
	assertTrue(exceptionResolvers.getValue().get(2) instanceof DefaultHandlerExceptionResolver);
	assertTrue(converters.getValue().size() > 0);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:DelegatingWebMvcConfigurationTests.java

示例3: 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

示例4: handlerExceptionResolver

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入依赖的package包/类
@Test
public void handlerExceptionResolver() throws Exception {
	HandlerExceptionResolverComposite compositeResolver =
		(HandlerExceptionResolverComposite) mvcConfiguration.handlerExceptionResolver();

	assertEquals(0, compositeResolver.getOrder());

	List<HandlerExceptionResolver> expectedResolvers = compositeResolver.getExceptionResolvers();

	assertEquals(ExceptionHandlerExceptionResolver.class, expectedResolvers.get(0).getClass());
	assertEquals(ResponseStatusExceptionResolver.class, expectedResolvers.get(1).getClass());
	assertEquals(DefaultHandlerExceptionResolver.class, expectedResolvers.get(2).getClass());

	ExceptionHandlerExceptionResolver eher = (ExceptionHandlerExceptionResolver) expectedResolvers.get(0);
	assertNotNull(eher.getApplicationContext());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:WebMvcConfigurationSupportTests.java

示例5: 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

示例6: handlerExceptionResolver

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void handlerExceptionResolver() throws Exception {
	ApplicationContext context = initContext(WebConfig.class);
	HandlerExceptionResolverComposite compositeResolver =
			context.getBean("handlerExceptionResolver", HandlerExceptionResolverComposite.class);

	assertEquals(0, compositeResolver.getOrder());
	List<HandlerExceptionResolver> expectedResolvers = compositeResolver.getExceptionResolvers();

	assertEquals(ExceptionHandlerExceptionResolver.class, expectedResolvers.get(0).getClass());
	assertEquals(ResponseStatusExceptionResolver.class, expectedResolvers.get(1).getClass());
	assertEquals(DefaultHandlerExceptionResolver.class, expectedResolvers.get(2).getClass());

	ExceptionHandlerExceptionResolver eher = (ExceptionHandlerExceptionResolver) expectedResolvers.get(0);
	assertNotNull(eher.getApplicationContext());

	DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(eher);
	List<Object> interceptors = (List<Object>) fieldAccessor.getPropertyValue("responseBodyAdvice");
	assertEquals(1, interceptors.size());
	assertEquals(JsonViewResponseBodyAdvice.class, interceptors.get(0).getClass());

	LocaleContextHolder.setLocale(Locale.ENGLISH);
	try {
		ResponseStatusExceptionResolver rser = (ResponseStatusExceptionResolver) expectedResolvers.get(1);
		MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
		MockHttpServletResponse response = new MockHttpServletResponse();
		rser.resolveException(request, response, context.getBean(TestController.class), new UserAlreadyExistsException());
		assertEquals("User already exists!", response.getErrorMessage());
	}
	finally {
		LocaleContextHolder.resetLocaleContext();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:35,代码来源:WebMvcConfigurationSupportTests.java

示例7: testMessageConverters

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入依赖的package包/类
@Test
public void testMessageConverters() {
	loadBeanDefinitions("mvc-config-message-converters.xml");
	verifyMessageConverters(appContext.getBean(RequestMappingHandlerAdapter.class), true);
	verifyMessageConverters(appContext.getBean(ExceptionHandlerExceptionResolver.class), true);
	verifyRequestResponseBodyAdvice(appContext.getBean(RequestMappingHandlerAdapter.class));
	verifyResponseBodyAdvice(appContext.getBean(ExceptionHandlerExceptionResolver.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:AnnotationDrivenBeanDefinitionParserTests.java

示例8: createExceptionHandlerExceptionResolver

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入依赖的package包/类
@Override
protected ExceptionHandlerExceptionResolver createExceptionHandlerExceptionResolver() {
	if (this.mvcRegistrations != null && this.mvcRegistrations
			.getExceptionHandlerExceptionResolver() != null) {
		return this.mvcRegistrations.getExceptionHandlerExceptionResolver();
	}
	return super.createExceptionHandlerExceptionResolver();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:WebMvcAutoConfiguration.java

示例9: configureHandlerExceptionResolvers

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入依赖的package包/类
@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
    final ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver();
    resolver.setWarnLogCategory(resolver.getClass()
            .getName());
    exceptionResolvers.add(resolver);
}
 
开发者ID:dschulten,项目名称:hydra-java,代码行数:8,代码来源:XhtmlResourceMessageConverterTest.java

示例10: getHandlerExceptionResolverComposite

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入依赖的package包/类
@Bean
public HandlerExceptionResolverComposite getHandlerExceptionResolverComposite() {
    HandlerExceptionResolverComposite result = new HandlerExceptionResolverComposite();
    List<HandlerExceptionResolver> resolverList = new ArrayList<>();
    resolverList.add(new ExceptionHandlerExceptionResolver());
    resolverList.add(new ResponseStatusExceptionResolver());
    resolverList.add(new Error500Resolver());
    resolverList.add(new DefaultHandlerExceptionResolver());
    result.setExceptionResolvers(resolverList);
    return result;
}
 
开发者ID:srinikandula,项目名称:mybus,代码行数:12,代码来源:WebApplicationConfig.java

示例11: configureMessagesExceptionArgumentResolvers

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入依赖的package包/类
/**
 * adds a FlashMessagesMethodArgumentResolver to handlerExceptionResolver's argument resolvers
 */
@PostConstruct
private void configureMessagesExceptionArgumentResolvers() {
    this.handlerExceptionResolver = this.applicationContext.getBean("handlerExceptionResolver", HandlerExceptionResolver.class);

    for (final HandlerExceptionResolver resolver : ((HandlerExceptionResolverComposite) this.handlerExceptionResolver).getExceptionResolvers()) {
        if (resolver instanceof ExceptionHandlerExceptionResolver) {
            configureCustomHandlerMethodArgumentResolver((ExceptionHandlerExceptionResolver) resolver);
        }
    }
}
 
开发者ID:jeslopalo,项目名称:flash-messages,代码行数:14,代码来源:FlashMessagesConfigurationSupport.java

示例12: 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

示例13: it_should_add_exception_argument_resolver

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入依赖的package包/类
@Test
public void it_should_add_exception_argument_resolver() {
    final HandlerExceptionResolver handlerExceptionResolver = this.context.getBean(HandlerExceptionResolver.class);

    assertThat(handlerExceptionResolver).isInstanceOf(HandlerExceptionResolverComposite.class);
    for (final HandlerExceptionResolver resolver : ((HandlerExceptionResolverComposite) handlerExceptionResolver).getExceptionResolvers()) {
        if (resolver instanceof ExceptionHandlerExceptionResolver) {
            assertThat(((ExceptionHandlerExceptionResolver) resolver).getArgumentResolvers().getResolvers().get(0))
                .isInstanceOf(FlashMessagesMethodArgumentResolver.class);
        }
    }
}
 
开发者ID:jeslopalo,项目名称:flash-messages,代码行数:13,代码来源:FlashMessagesConfigurationSupportSpecs.java

示例14: exceptionHandlerExceptionResolver

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入依赖的package包/类
@Bean
public ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver() {
    ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver();
    resolver.setWarnLogCategory("parkandride");
    resolver.setMessageConverters(messageConverters.getConverters());
    return resolver;
}
 
开发者ID:HSLdevcom,项目名称:parkandrideAPI,代码行数:8,代码来源:Application.java

示例15: createExceptionResolver

import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; //导入依赖的package包/类
private ExceptionHandlerExceptionResolver createExceptionResolver() {
  ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver() {
    protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) {
      Method method = new ExceptionHandlerMethodResolver(JsonErrorHandler.class).resolveMethod(exception);
      return new ServletInvocableHandlerMethod(jsonErrorHandler, method);
    }
  };
  List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
  messageConverters.add(new FormHttpMessageConverter());
  messageConverters.add(new StringHttpMessageConverter());
  messageConverters.add(new MappingJackson2HttpMessageConverter());
  exceptionResolver.setMessageConverters(messageConverters);
  exceptionResolver.afterPropertiesSet();
  return exceptionResolver;
}
 
开发者ID:exo-archives,项目名称:acceptance,代码行数:16,代码来源:VCSRepositoryCRUDControllerTest.java


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