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


Java DefaultHandlerExceptionResolver类代码示例

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


DefaultHandlerExceptionResolver类属于org.springframework.web.servlet.mvc.support包,在下文中一共展示了DefaultHandlerExceptionResolver类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addDefaultHandlerExceptionResolvers

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的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: supportsAllDefaultHandlerExceptionResolverExceptionTypes

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的package包/类
@Test
public void supportsAllDefaultHandlerExceptionResolverExceptionTypes() throws Exception {

	Class<ResponseEntityExceptionHandler> clazz = ResponseEntityExceptionHandler.class;
	Method handleExceptionMethod = clazz.getMethod("handleException", Exception.class, WebRequest.class);
	ExceptionHandler annotation = handleExceptionMethod.getAnnotation(ExceptionHandler.class);
	List<Class<?>> exceptionTypes = Arrays.asList(annotation.value());

	for (Method method : DefaultHandlerExceptionResolver.class.getDeclaredMethods()) {
		Class<?>[] paramTypes = method.getParameterTypes();
		if (method.getName().startsWith("handle") && (paramTypes.length == 4)) {
			String name = paramTypes[0].getSimpleName();
			assertTrue("@ExceptionHandler is missing " + name, exceptionTypes.contains(paramTypes[0]));
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:ResponseEntityExceptionHandlerTests.java

示例3: handlerExceptionResolver

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的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

示例4: handlerExceptionResolver

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的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: configureHandlerExceptionResolvers

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的package包/类
@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
    // NOTE: Do not change the order! Only first resolution is used.

    // By default Spring MVC does not log exceptions from @Controller methods.
    if (!runtimeEnvironmentUtil.isIntegrationTestEnvironment()) {
        exceptionResolvers.add(new LoggingHandlerExceptionResolver());
    }
    // Process exception using @ExceptionHandler method inside @Controller
    exceptionResolvers.add(exceptionHandlerExceptionResolver());
    // Return status code specified using @ResponseStatus in exception class
    exceptionResolvers.add(new ResponseStatusExceptionResolver());
    // Send HTTP status code depending on the exception which is mapped to error page in web.xml
    exceptionResolvers.add(new DefaultHandlerExceptionResolver());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:16,代码来源:WebMVCConfig.java

示例6: setup

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的package包/类
@Before
public void setup() {
	this.servletRequest = new MockHttpServletRequest("GET", "/");
	this.servletResponse = new MockHttpServletResponse();
	this.request = new ServletWebRequest(this.servletRequest, this.servletResponse);

	this.exceptionHandlerSupport = new ApplicationExceptionHandler();
	this.defaultExceptionResolver = new DefaultHandlerExceptionResolver();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:ResponseEntityExceptionHandlerTests.java

示例7: handlerExceptionResolver

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的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

示例8: configureExceptionResolvers

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的package包/类
@Test
public void configureExceptionResolvers() throws Exception {
	List<WebMvcConfigurer> configurers = new ArrayList<WebMvcConfigurer>();
	configurers.add(new WebMvcConfigurerAdapter() {
		@Override
		public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
			exceptionResolvers.add(new DefaultHandlerExceptionResolver());
		}
	});
	delegatingConfig.setConfigurers(configurers);

	HandlerExceptionResolverComposite composite =
		(HandlerExceptionResolverComposite) delegatingConfig.handlerExceptionResolver();
	assertEquals("Only one custom converter is expected", 1, composite.getExceptionResolvers().size());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:DelegatingWebMvcConfigurationTests.java

示例9: exceptionResolvers

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的package包/类
protected HandlerExceptionResolver[] exceptionResolvers() {
  HandlerExceptionResolver
      defaultHandlerExceptionResolver =
      new DefaultHandlerExceptionResolver();
  return new HandlerExceptionResolver[]{uncheckedExceptionResolver(),
      defaultHandlerExceptionResolver};
}
 
开发者ID:epam-debrecen-rft-2015,项目名称:atsy,代码行数:8,代码来源:AbstractControllerTest.java

示例10: getHandlerExceptionResolverComposite

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的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: setup

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的package包/类
@Before
public void setup() {
	this.servletRequest = new MockHttpServletRequest();
	this.servletResponse = new MockHttpServletResponse();
	this.request = new ServletWebRequest(this.servletRequest, this.servletResponse);

	this.exceptionHandlerSupport = new ApplicationExceptionHandler();
	this.defaultExceptionResolver = new DefaultHandlerExceptionResolver();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:10,代码来源:ResponseEntityExceptionHandlerTests.java

示例12: supportsAllDefaultHandlerExceptionResolverExceptionTypes

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的package包/类
@Test
public void supportsAllDefaultHandlerExceptionResolverExceptionTypes() throws Exception {

	Method annotMethod = ResponseEntityExceptionHandler.class.getMethod("handleException", Exception.class, WebRequest.class);
	ExceptionHandler annot = annotMethod.getAnnotation(ExceptionHandler.class);
	List<Class<? extends Throwable>> supportedTypes = Arrays.asList(annot.value());

	for (Method method : DefaultHandlerExceptionResolver.class.getDeclaredMethods()) {
		Class<?>[] paramTypes = method.getParameterTypes();
		if (method.getName().startsWith("handle") && (paramTypes.length == 4)) {
			String name = paramTypes[0].getSimpleName();
			assertTrue("@ExceptionHandler is missing " + name, supportedTypes.contains(paramTypes[0]));
		}
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:16,代码来源:ResponseEntityExceptionHandlerTests.java

示例13: initServlet

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的package包/类
/**
 * Initialize a DispatcherServlet instance registering zero or more controller classes
 * and also providing additional bean definitions through a callback.
 */
@SuppressWarnings("serial")
protected WebApplicationContext initServlet(
		final ApplicationContextInitializer<GenericWebApplicationContext> initializer,
		final Class<?>... controllerClasses) throws ServletException {

	final GenericWebApplicationContext wac = new GenericWebApplicationContext();

	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			for (Class<?> clazz : controllerClasses) {
				wac.registerBeanDefinition(clazz.getSimpleName(), new RootBeanDefinition(clazz));
			}

			Class<?> mappingType = RequestMappingHandlerMapping.class;
			RootBeanDefinition beanDef = new RootBeanDefinition(mappingType);
			beanDef.getPropertyValues().add("removeSemicolonContent", "false");
			wac.registerBeanDefinition("handlerMapping", beanDef);

			Class<?> adapterType = RequestMappingHandlerAdapter.class;
			wac.registerBeanDefinition("handlerAdapter", new RootBeanDefinition(adapterType));

			Class<?> resolverType = ExceptionHandlerExceptionResolver.class;
			wac.registerBeanDefinition("requestMappingResolver", new RootBeanDefinition(resolverType));

			resolverType = ResponseStatusExceptionResolver.class;
			wac.registerBeanDefinition("responseStatusResolver", new RootBeanDefinition(resolverType));

			resolverType = DefaultHandlerExceptionResolver.class;
			wac.registerBeanDefinition("defaultResolver", new RootBeanDefinition(resolverType));

			if (initializer != null) {
				initializer.initialize(wac);
			}

			wac.refresh();
			return wac;
		}
	};

	servlet.init(new MockServletConfig());

	return wac;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:49,代码来源:AbstractServletHandlerMethodTests.java

示例14: addDefaultHandlerExceptionResolvers

import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; //导入依赖的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.support.DefaultHandlerExceptionResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。