Class AbstractNamedValueMethodArgumentResolver

  • java.lang.Object
  • All Implemented Interfaces:
    Direct Known Subclasses:
    DestinationVariableMethodArgumentResolver, HeaderMethodArgumentResolver

    public abstract class AbstractNamedValueMethodArgumentResolver
    extends java.lang.Object
    implements HandlerMethodArgumentResolver
    Abstract base class for resolving method arguments from a named value. Message 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:

    • Obtain named value information for a method parameter
    • Resolve names into argument values
    • Handle missing argument values when argument values are required
    • Optionally handle a resolved value

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

    A ConversionService may be used to apply type conversion to the resolved argument value if it doesn't match the method parameter type.

    Rossen Stoyanchev, Juergen Hoeller
    • Constructor Detail

      • AbstractNamedValueMethodArgumentResolver

        protected AbstractNamedValueMethodArgumentResolver(ConversionService cs,
                                                           ConfigurableBeanFactory beanFactory)
        Constructor with a ConversionService and a BeanFactory.
        cs - conversion service for converting values to match the target method parameter type
        beanFactory - a bean factory to use for resolving ${...} placeholder and #{...} SpEL expressions in default values, or null if default values are not expected to contain expressions
    • Method Detail

      • resolveArgumentInternal

        protected abstract java.lang.Object resolveArgumentInternal(MethodParameter parameter,
                                                                              Message<?> message,
                                                                              java.lang.String name)
                                                                       throws java.lang.Exception
        Resolves the given parameter type and value name into an argument value.
        parameter - the method parameter to resolve to an argument value
        message - the current request
        name - the name of the value being resolved
        the resolved argument. May be null
        java.lang.Exception - in case of errors
      • handleMissingValue

        protected abstract void handleMissingValue(java.lang.String name,
                                                   MethodParameter parameter,
                                                   Message<?> message)
        Invoked when a named value is required, but resolveArgumentInternal(MethodParameter, Message, String) returned null and there is no default value. Subclasses typically throw an exception in this case.
        name - the name for the value
        parameter - the method parameter
        message - the message being processed
      • handleResolvedValue

        protected void handleResolvedValue(java.lang.Object arg,
                                           java.lang.String name,
                                           MethodParameter parameter,
                                           Message<?> message)
        Invoked after a value is resolved.
        arg - the resolved argument value
        name - the argument name
        parameter - the argument parameter type
        message - the message