• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ResponseStatusExceptionResolver类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: addDefaultHandlerExceptionResolvers

import org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver; //导入依赖的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.annotation.ResponseStatusExceptionResolver; //导入依赖的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: handlerExceptionResolver

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


示例4: extendHandlerExceptionResolvers

import org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver; //导入依赖的package包/类
@Override
public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
	exceptionResolvers.forEach(resolver -> {
		if (resolver instanceof ResponseStatusExceptionResolver)
			((ResponseStatusExceptionResolver) resolver).setMessageSource(null);
	});
}
 
开发者ID:yushijinhun,项目名称:akir,代码行数:8,代码来源:MvcConfig.java


示例5: configureHandlerExceptionResolvers

import org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver; //导入依赖的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: handlerExceptionResolver

import org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver; //导入依赖的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: getHandlerExceptionResolverComposite

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


示例8: initServlet

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


示例9: addDefaultHandlerExceptionResolvers

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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HangingEvent类代码示例发布时间:2022-05-22
下一篇:
Java RealmsScreen类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap