Use MessageSource for @ExceptionHandler methods

Follow-up for commit bb816c123c

See gh-27203
This commit is contained in:
Yanming Zhou
2021-07-23 10:00:23 +08:00
committed by Rossen Stoyanchev
parent 5b3f11c543
commit f2be4e9320
5 changed files with 72 additions and 3 deletions

View File

@@ -102,11 +102,20 @@ public class HandlerMethod {
* Create an instance from a bean instance and a method.
*/
public HandlerMethod(Object bean, Method method) {
this(bean, method, null);
}
/**
* Variant of {@link #HandlerMethod(Object, Method)} that
* also accepts a {@link MessageSource}.
*/
public HandlerMethod(Object bean, Method method, @Nullable MessageSource messageSource) {
Assert.notNull(bean, "Bean is required");
Assert.notNull(method, "Method is required");
this.bean = bean;
this.beanFactory = null;
this.messageSource = null;
this.messageSource = messageSource;
this.beanType = ClassUtils.getUserClass(bean);
this.method = method;
this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);

View File

@@ -20,6 +20,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.springframework.context.MessageSource;
import org.springframework.core.CoroutinesUtils;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.KotlinDetector;
@@ -71,6 +72,14 @@ public class InvocableHandlerMethod extends HandlerMethod {
super(bean, method);
}
/**
* Variant of {@link #InvocableHandlerMethod(Object, Method)} that
* also accepts a {@link MessageSource}.
*/
public InvocableHandlerMethod(Object bean, Method method, @Nullable MessageSource messageSource) {
super(bean, method, messageSource);
}
/**
* Construct a new handler method with the given bean instance, method name and parameters.
* @param bean the object bean