Add option to extend exception resolvers
Issue: SPR-13931
This commit is contained in:
@@ -713,6 +713,14 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to extend or modify the list of converters after it
|
||||
* has been configured. This may be useful for example to allow default
|
||||
* converters to be registered and then insert a custom converter through
|
||||
* this method.
|
||||
* @param converters the list of configured converters to extend.
|
||||
* @since 4.1.3
|
||||
*/
|
||||
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
}
|
||||
|
||||
@@ -813,6 +821,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
addDefaultHandlerExceptionResolvers(exceptionResolvers);
|
||||
}
|
||||
|
||||
extendHandlerExceptionResolvers(exceptionResolvers);
|
||||
HandlerExceptionResolverComposite composite = new HandlerExceptionResolverComposite();
|
||||
composite.setOrder(0);
|
||||
composite.setExceptionResolvers(exceptionResolvers);
|
||||
@@ -831,6 +840,17 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
protected void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to extend or modify the list of
|
||||
* {@link HandlerExceptionResolver}s after it has been configured. This may
|
||||
* be useful for example to allow default resolvers to be registered and then
|
||||
* insert a custom one through this method.
|
||||
* @param exceptionResolvers the list of configured resolvers to extend.
|
||||
* @since 4.3.1
|
||||
*/
|
||||
protected void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A method available to subclasses for adding default {@link HandlerExceptionResolver}s.
|
||||
* <p>Adds the following exception resolvers:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -130,6 +130,16 @@ public interface WebMvcConfigurer {
|
||||
*/
|
||||
void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers);
|
||||
|
||||
/**
|
||||
* A hook for extending or modifying the list of
|
||||
* {@link HandlerExceptionResolver}s after it has been configured. This may
|
||||
* be useful for example to allow default resolvers to be registered and then
|
||||
* insert a custom one through this method.
|
||||
* @param exceptionResolvers the list of configured resolvers to extend.
|
||||
* @since 4.3.1
|
||||
*/
|
||||
void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers);
|
||||
|
||||
/**
|
||||
* Add Spring MVC lifecycle interceptors for pre- and post-processing of
|
||||
* controller method invocations. Interceptors can be registered to apply
|
||||
|
||||
@@ -116,6 +116,14 @@ public abstract class WebMvcConfigurerAdapter implements WebMvcConfigurer {
|
||||
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>This implementation is empty.
|
||||
*/
|
||||
@Override
|
||||
public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>This implementation is empty.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,7 @@ import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||
|
||||
/**
|
||||
* An {@link WebMvcConfigurer} implementation that delegates to other {@link WebMvcConfigurer} instances.
|
||||
* A {@link WebMvcConfigurer} that delegates to one or more others.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
@@ -106,6 +106,13 @@ class WebMvcConfigurerComposite implements WebMvcConfigurer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
|
||||
for (WebMvcConfigurer delegate : this.delegates) {
|
||||
delegate.configureHandlerExceptionResolvers(exceptionResolvers);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
for (WebMvcConfigurer delegate : this.delegates) {
|
||||
|
||||
Reference in New Issue
Block a user