类 ContentNegotiationManagerFactoryBean

java.lang.Object
cn.taketoday.web.accept.ContentNegotiationManagerFactoryBean
所有已实现的接口:
cn.taketoday.beans.factory.FactoryBean<ContentNegotiationManager>, cn.taketoday.beans.factory.InitializingBean

public class ContentNegotiationManagerFactoryBean extends Object implements cn.taketoday.beans.factory.FactoryBean<ContentNegotiationManager>, cn.taketoday.beans.factory.InitializingBean
Factory to create a ContentNegotiationManager and configure it with ContentNegotiationStrategy instances.

This factory offers properties that in turn result in configuring the underlying strategies. The table below shows the property names, their default settings, as well as the strategies that they help to configure:

Property Setter Default Value Underlying Strategy Enabled Or Not
favorParameter false ParameterContentNegotiationStrategy Off
ignoreAcceptHeader false HeaderContentNegotiationStrategy Enabled
favorPathExtension false PathExtensionContentNegotiationStrategy Off
defaultContentType null FixedContentNegotiationStrategy Off
defaultContentTypeStrategy null ContentNegotiationStrategy Off

Alternatively you can avoid use of the above convenience builder methods and set the exact strategies to use via setStrategies(List).

从以下版本开始:
4.0
作者:
Rossen Stoyanchev, Brian Clozel, Harry Yang
  • 字段详细资料

    • strategies

      @Nullable private List<ContentNegotiationStrategy> strategies
    • favorParameter

      private boolean favorParameter
    • parameterName

      private String parameterName
    • ignoreUnknownPathExtensions

      private boolean ignoreUnknownPathExtensions
    • favorPathExtension

      private boolean favorPathExtension
    • mediaTypes

      private final Map<String,MediaType> mediaTypes
    • useRegisteredExtensionsOnly

      @Nullable private Boolean useRegisteredExtensionsOnly
    • ignoreAcceptHeader

      private boolean ignoreAcceptHeader
    • defaultNegotiationStrategy

      @Nullable private ContentNegotiationStrategy defaultNegotiationStrategy
    • contentNegotiationManager

      @Nullable private ContentNegotiationManager contentNegotiationManager
    • servletContext

      @Nullable private Object servletContext
  • 构造器详细资料

    • ContentNegotiationManagerFactoryBean

      public ContentNegotiationManagerFactoryBean()
  • 方法详细资料

    • setStrategies

      public void setStrategies(@Nullable List<ContentNegotiationStrategy> strategies)
      Set the exact list of strategies to use.

      Note: use of this method is mutually exclusive with use of all other setters in this class which customize a default, fixed set of strategies. See class level doc for more details.

      参数:
      strategies - the strategies to use
    • setFavorParameter

      public void setFavorParameter(boolean favorParameter)
      Whether a request parameter ("format" by default) should be used to determine the requested media type. For this option to work you must register media type mappings.

      By default this is set to false.

      另请参阅:
    • setParameterName

      public void setParameterName(String parameterName)
      Set the query parameter name to use when setFavorParameter(boolean) is on.

      The default parameter name is "format".

    • setFavorPathExtension

      public void setFavorPathExtension(boolean favorPathExtension)
      Whether the path extension in the URL path should be used to determine the requested media type.

      By default this is set to false in which case path extensions have no impact on content negotiation.

    • setMediaTypes

      public void setMediaTypes(Properties mediaTypes)
      Add a mapping from a key to a MediaType where the key are normalized to lowercase and may have been extracted from a path extension, a filename extension, or passed as a query parameter.

      The parameter strategy requires such mappings in order to work while the path extension strategy can fall back on lookups via and MediaType.

      Note: Mappings registered here may be accessed via ContentNegotiationManager.getMediaTypeMappings() and may be used not only in the parameter and path extension strategies.

      参数:
      mediaTypes - media type mappings
      另请参阅:
    • addMediaType

      public void addMediaType(String key, MediaType mediaType)
      An alternative to setMediaTypes(java.util.Properties) for programmatic registrations.
    • addMediaTypes

      public void addMediaTypes(@Nullable Map<String,MediaType> mediaTypes)
      An alternative to setMediaTypes(java.util.Properties) for programmatic registrations.
    • setIgnoreUnknownPathExtensions

      public void setIgnoreUnknownPathExtensions(boolean ignore)
      Whether to ignore requests with path extension that cannot be resolved to any media type. Setting this to false will result in an HttpMediaTypeNotAcceptableException if there is no match.

      By default this is set to true.

    • setUseRegisteredExtensionsOnly

      public void setUseRegisteredExtensionsOnly(boolean useRegisteredExtensionsOnly)
      When setFavorParameter(boolean) is set, this property determines whether to use only registered MediaType mappings or to allow dynamic resolution, e.g. via MediaType.fromFileName(String) MediaTypeFactory}.

      By default this is not set in which case dynamic resolution is on.

    • setIgnoreAcceptHeader

      public void setIgnoreAcceptHeader(boolean ignoreAcceptHeader)
      Whether to disable checking the 'Accept' request header.

      By default this value is set to false.

    • setDefaultContentType

      public void setDefaultContentType(MediaType contentType)
      Set the default content type to use when no content type is requested.

      By default this is not set.

      另请参阅:
    • setDefaultContentTypes

      public void setDefaultContentTypes(List<MediaType> contentTypes)
      Set the default content types to use when no content type is requested.

      By default this is not set.

      另请参阅:
    • setDefaultContentTypeStrategy

      public void setDefaultContentTypeStrategy(ContentNegotiationStrategy strategy)
      Set a custom ContentNegotiationStrategy to use to determine the content type to use when no content type is requested.

      By default this is not set.

      另请参阅:
    • setServletContext

      public void setServletContext(@Nullable Object servletContext)
    • afterPropertiesSet

      public void afterPropertiesSet()
      指定者:
      afterPropertiesSet 在接口中 cn.taketoday.beans.factory.InitializingBean
    • build

      public ContentNegotiationManager build()
      Create and initialize a ContentNegotiationManager instance.
    • getObject

      @Nullable public ContentNegotiationManager getObject()
      指定者:
      getObject 在接口中 cn.taketoday.beans.factory.FactoryBean<ContentNegotiationManager>
    • getObjectType

      public Class<?> getObjectType()
      指定者:
      getObjectType 在接口中 cn.taketoday.beans.factory.FactoryBean<ContentNegotiationManager>
    • isSingleton

      public boolean isSingleton()
      指定者:
      isSingleton 在接口中 cn.taketoday.beans.factory.FactoryBean<ContentNegotiationManager>