diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java index 678fc300d0..5c08b33aac 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java @@ -39,6 +39,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; * Abstract base class for resolving method arguments from a named value. * Request parameters, request headers, and path variables are examples of named * values. Each may have a name, a required flag, and a default value. + * *

Subclasses define how to do the following: *

+ * *

A default value string can contain ${...} placeholders and Spring Expression * Language #{...} expressions. For this to work a * {@link ConfigurableBeanFactory} must be supplied to the class constructor. + * *

A {@link WebDataBinder} is created to apply type conversion to the resolved * argument value if it doesn't match the method parameter type. * @@ -78,7 +81,8 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle */ public AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) { this.configurableBeanFactory = beanFactory; - this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null); + this.expressionContext = + (beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null); } @@ -204,7 +208,9 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle * @param request the current request * @since 4.3 */ - protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { + protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) + throws Exception { + handleMissingValue(name, parameter); } @@ -241,7 +247,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle * @param arg the resolved argument value * @param name the argument name * @param parameter the argument parameter type - * @param mavContainer the {@link ModelAndViewContainer}, which may be {@code null} + * @param mavContainer the {@link ModelAndViewContainer} (may be {@code null}) * @param webRequest the current request */ protected void handleResolvedValue(Object arg, String name, MethodParameter parameter, diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java index bc06561985..e7463e05e9 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.Part; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -181,7 +182,9 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod } @Override - protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { + protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) + throws Exception { + HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class); if (MultipartResolutionDelegate.isMultipartArgument(parameter)) { if (!MultipartResolutionDelegate.isMultipartRequest(servletRequest)) { @@ -192,7 +195,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod } } else { - throw new MissingServletRequestParameterException(name, parameter.getNestedParameterType().getSimpleName()); + throw new MissingServletRequestParameterException(name, + parameter.getNestedParameterType().getSimpleName()); } } @@ -201,8 +205,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod UriComponentsBuilder builder, Map uriVariables, ConversionService conversionService) { Class paramType = parameter.getNestedParameterType(); - if (Map.class.isAssignableFrom(paramType) || MultipartFile.class == paramType || - "javax.servlet.http.Part".equals(paramType.getName())) { + if (Map.class.isAssignableFrom(paramType) || MultipartFile.class == paramType || Part.class == paramType) { return; }