Class AbstractNamedValueArgumentResolver

java.lang.Object
org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport
org.springframework.web.reactive.result.method.annotation.AbstractNamedValueArgumentResolver
All Implemented Interfaces:
HandlerMethodArgumentResolver
Direct Known Subclasses:
AbstractNamedValueSyncArgumentResolver, SessionAttributeMethodArgumentResolver

public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodArgumentResolverSupport
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:

  • 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.

Since:
5.0
Author:
Rossen Stoyanchev
  • Constructor Details

    • AbstractNamedValueArgumentResolver

      public AbstractNamedValueArgumentResolver(@Nullable org.springframework.beans.factory.config.ConfigurableBeanFactory factory, org.springframework.core.ReactiveAdapterRegistry registry)
      Create a new AbstractNamedValueArgumentResolver instance.
      Parameters:
      factory - 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
      registry - for checking reactive type wrappers
  • Method Details

    • resolveArgument

      public reactor.core.publisher.Mono<Object> resolveArgument(org.springframework.core.MethodParameter parameter, BindingContext bindingContext, org.springframework.web.server.ServerWebExchange exchange)
      Description copied from interface: HandlerMethodArgumentResolver
      Resolve the value for the method parameter.
      Parameters:
      parameter - the method parameter
      bindingContext - the binding context to use
      exchange - the current exchange
      Returns:
      Mono for the argument value, possibly empty
    • createNamedValueInfo

      protected abstract AbstractNamedValueArgumentResolver.NamedValueInfo createNamedValueInfo(org.springframework.core.MethodParameter parameter)
      Create the AbstractNamedValueArgumentResolver.NamedValueInfo object for the given method parameter. Implementations typically retrieve the method annotation by means of MethodParameter.getParameterAnnotation(Class).
      Parameters:
      parameter - the method parameter
      Returns:
      the named value information
    • resolveName

      protected abstract reactor.core.publisher.Mono<Object> resolveName(String name, org.springframework.core.MethodParameter parameter, org.springframework.web.server.ServerWebExchange exchange)
      Resolve the given parameter type and value name into an argument value.
      Parameters:
      name - the name of the value being resolved
      parameter - the method parameter to resolve to an argument value (pre-nested in case of a Optional declaration)
      exchange - the current exchange
      Returns:
      the resolved argument (may be empty Mono)
    • handleMissingValue

      protected void handleMissingValue(String name, org.springframework.core.MethodParameter parameter, org.springframework.web.server.ServerWebExchange exchange)
      Invoked when a named value is required, but resolveName(String, MethodParameter, ServerWebExchange) returned null and there is no default value. Subclasses typically throw an exception in this case.
      Parameters:
      name - the name for the value
      parameter - the method parameter
      exchange - the current exchange
    • handleMissingValue

      protected void handleMissingValue(String name, org.springframework.core.MethodParameter parameter)
      Invoked when a named value is required, but resolveName(String, MethodParameter, ServerWebExchange) returned null and there is no default value. Subclasses typically throw an exception in this case.
      Parameters:
      name - the name for the value
      parameter - the method parameter
    • handleResolvedValue

      protected void handleResolvedValue(@Nullable Object arg, String name, org.springframework.core.MethodParameter parameter, org.springframework.ui.Model model, org.springframework.web.server.ServerWebExchange exchange)
      Invoked after a value is resolved.
      Parameters:
      arg - the resolved argument value
      name - the argument name
      parameter - the argument parameter type
      model - the model
      exchange - the current exchange