use of org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver in project spring-framework by spring-projects.
the class WebMvcConfigurationSupport method addDefaultHandlerExceptionResolvers.
/**
* 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 exceptionHandlerResolver = createExceptionHandlerExceptionResolver();
exceptionHandlerResolver.setContentNegotiationManager(mvcContentNegotiationManager());
exceptionHandlerResolver.setMessageConverters(getMessageConverters());
exceptionHandlerResolver.setCustomArgumentResolvers(getArgumentResolvers());
exceptionHandlerResolver.setCustomReturnValueHandlers(getReturnValueHandlers());
if (jackson2Present) {
exceptionHandlerResolver.setResponseBodyAdvice(Collections.singletonList(new JsonViewResponseBodyAdvice()));
}
exceptionHandlerResolver.setApplicationContext(this.applicationContext);
exceptionHandlerResolver.afterPropertiesSet();
exceptionResolvers.add(exceptionHandlerResolver);
ResponseStatusExceptionResolver responseStatusResolver = new ResponseStatusExceptionResolver();
responseStatusResolver.setMessageSource(this.applicationContext);
exceptionResolvers.add(responseStatusResolver);
exceptionResolvers.add(new DefaultHandlerExceptionResolver());
}
use of org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver in project spring-framework by spring-projects.
the class WebMvcConfigurationSupport method addDefaultHandlerExceptionResolvers.
/**
* A method available to subclasses for adding default
* {@link HandlerExceptionResolver HandlerExceptionResolvers}.
* <p>Adds the following exception resolvers:
* <ul>
* <li>{@link ExceptionHandlerExceptionResolver} for handling exceptions through
* {@link org.springframework.web.bind.annotation.ExceptionHandler} methods.
* <li>{@link ResponseStatusExceptionResolver} for exceptions annotated with
* {@link org.springframework.web.bind.annotation.ResponseStatus}.
* <li>{@link DefaultHandlerExceptionResolver} for resolving known Spring exception types
* </ul>
*/
protected final void addDefaultHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers, ContentNegotiationManager mvcContentNegotiationManager) {
ExceptionHandlerExceptionResolver exceptionHandlerResolver = createExceptionHandlerExceptionResolver();
exceptionHandlerResolver.setContentNegotiationManager(mvcContentNegotiationManager);
exceptionHandlerResolver.setMessageConverters(getMessageConverters());
exceptionHandlerResolver.setCustomArgumentResolvers(getArgumentResolvers());
exceptionHandlerResolver.setCustomReturnValueHandlers(getReturnValueHandlers());
if (jackson2Present) {
exceptionHandlerResolver.setResponseBodyAdvice(Collections.singletonList(new JsonViewResponseBodyAdvice()));
}
if (this.applicationContext != null) {
exceptionHandlerResolver.setApplicationContext(this.applicationContext);
}
exceptionHandlerResolver.afterPropertiesSet();
exceptionResolvers.add(exceptionHandlerResolver);
ResponseStatusExceptionResolver responseStatusResolver = new ResponseStatusExceptionResolver();
responseStatusResolver.setMessageSource(this.applicationContext);
exceptionResolvers.add(responseStatusResolver);
exceptionResolvers.add(new DefaultHandlerExceptionResolver());
}
use of org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver in project spring-framework by spring-projects.
the class ResponseEntityExceptionHandlerTests method setup.
@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();
}
use of org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver in project spring-framework by spring-projects.
the class DelegatingWebMvcConfigurationTests method configureExceptionResolvers.
@Test
public void configureExceptionResolvers() {
WebMvcConfigurer configurer = new WebMvcConfigurer() {
@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
resolvers.add(new DefaultHandlerExceptionResolver());
}
};
webMvcConfig.setConfigurers(Collections.singletonList(configurer));
HandlerExceptionResolverComposite composite = (HandlerExceptionResolverComposite) webMvcConfig.handlerExceptionResolver(webMvcConfig.mvcContentNegotiationManager());
assertThat(composite.getExceptionResolvers().size()).as("Only one custom converter is expected").isEqualTo(1);
}
use of org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver in project spring-boot by spring-projects.
the class CompositeHandlerExceptionResolver method extractResolvers.
private List<HandlerExceptionResolver> extractResolvers() {
List<HandlerExceptionResolver> list = new ArrayList<>(this.beanFactory.getBeansOfType(HandlerExceptionResolver.class).values());
list.remove(this);
AnnotationAwareOrderComparator.sort(list);
if (list.isEmpty()) {
list.add(new DefaultErrorAttributes());
list.add(new DefaultHandlerExceptionResolver());
}
return list;
}
Aggregations