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 |
favorPathExtension |
false (as of 5.3) | PathExtensionContentNegotiationStrategy |
Off |
ignoreAcceptHeader |
false | HeaderContentNegotiationStrategy |
Enabled |
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).
Deprecation Note: As of 5.2.4,
favorPathExtension and
ignoreUnknownPathExtensions
are deprecated in order to discourage using path extensions for content
negotiation and for request mapping with similar deprecations on
RequestMappingHandlerMapping. For further context, please read issue
#24719.
| Modifier and Type | Field and Description |
|---|---|
| private ContentNegotiationManager | |
| private ContentNegotiationStrategy | |
| private boolean | |
| private boolean | |
| private boolean | |
| private boolean | |
| private final Map | |
| private String | |
| private ServletContext | |
| private List | |
| private Boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addMediaType(String key, MediaType mediaType)
An alternative to |
| public void | addMediaTypes(Map<String, MediaType> mediaTypes)
An alternative to |
| public void | afterPropertiesSet()
Implements org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. |
| public ContentNegotiationManager | |
| public ContentNegotiationManager | getObject()
Implements org. Return an instance (possibly shared or independent) of the object managed by this factory. |
| public Class | getObjectType()
Implements org. Return the type of object that this FactoryBean creates,
or |
| public boolean | isSingleton()
Overrides default org. Is the object managed by this factory a singleton? |
| public void | setDefaultContentType(MediaType contentType)
Set the default content type to use when no content type is requested. |
| public void | setDefaultContentTypes(List<MediaType> contentTypes)
Set the default content types to use when no content type is requested. |
| public void | setDefaultContentTypeStrategy(ContentNegotiationStrategy strategy)
Set a custom |
| public void | setFavorParameter(boolean favorParameter)
Whether a request parameter ("format" by default) should be used to determine the requested media type. |
| public void | setFavorPathExtension(boolean favorPathExtension)
Deprecated
as of 5.2.4.
Whether the path extension in the URL path should be used to determine the requested media type. |
| public void | setIgnoreAcceptHeader(boolean ignoreAcceptHeader)
Whether to disable checking the 'Accept' request header. |
| public void | setIgnoreUnknownPathExtensions(boolean ignore)
Deprecated
as of 5.2.4. See class-level note on the deprecation of path
extension config options.
Whether to ignore requests with path extension that cannot be resolved to any media type. |
| public void | setMediaTypes(Properties
media type mappings 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. |
| public void | setParameterName(String parameterName)
Set the query parameter name to use when |
| public void | setServletContext(ServletContext
the ServletContext object to be used by this object servletContext)Implements org. Invoked by Spring to inject the ServletContext. |
| public void | setStrategies(List<ContentNegotiationStrategy>
the strategies to use strategies)Set the exact list of strategies to use. |
| public void | setUseJaf(boolean useJaf)
Deprecated
as of 5.0, in favor of
setUseRegisteredExtensionsOnly(boolean),
which has reverse behavior.
Indicate whether to use the Java Activation Framework as a fallback option to map from file extensions to media types. |
| public void | setUseRegisteredExtensionsOnly(boolean useRegisteredExtensionsOnly)
When |
| private boolean |
| contentNegotiationManager | back to summary |
|---|---|
| private ContentNegotiationManager contentNegotiationManager
| |
| defaultNegotiationStrategy | back to summary |
|---|---|
| private ContentNegotiationStrategy defaultNegotiationStrategy
| |
| favorParameter | back to summary |
|---|---|
| private boolean favorParameter | |
| favorPathExtension | back to summary |
|---|---|
| private boolean favorPathExtension | |
| ignoreAcceptHeader | back to summary |
|---|---|
| private boolean ignoreAcceptHeader | |
| ignoreUnknownPathExtensions | back to summary |
|---|---|
| private boolean ignoreUnknownPathExtensions | |
| mediaTypes | back to summary |
|---|---|
| private final Map<String, MediaType> mediaTypes | |
| parameterName | back to summary |
|---|---|
| private String parameterName | |
| servletContext | back to summary |
|---|---|
| private ServletContext servletContext
| |
| strategies | back to summary |
|---|---|
| private List<ContentNegotiationStrategy> strategies
| |
| useRegisteredExtensionsOnly | back to summary |
|---|---|
| private Boolean useRegisteredExtensionsOnly
| |
| ContentNegotiationManagerFactoryBean | back to summary |
|---|---|
| public ContentNegotiationManagerFactoryBean() | |
| addMediaType | back to summary |
|---|---|
| public void addMediaType(String key, MediaType mediaType) An alternative to | |
| addMediaTypes | back to summary |
|---|---|
| public void addMediaTypes(Map<String, MediaType> mediaTypes) An alternative to | |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() Implements org. Doc from org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
| |
| build | back to summary |
|---|---|
| public ContentNegotiationManager build() Create and initialize a
| |
| getObject | back to summary |
|---|---|
| public ContentNegotiationManager getObject() Implements org. Doc from org. Return an instance (possibly shared or independent) of the object managed by this factory. As with a If this FactoryBean is not fully initialized yet at the time of
the call (for example because it is involved in a circular reference),
throw a corresponding As of Spring 2.0, FactoryBeans are allowed to return
| |
| getObjectType | back to summary |
|---|---|
| public Class Implements org. Doc from org. Return the type of object that this FactoryBean creates,
or This allows one to check for specific types of beans without instantiating objects, for example on autowiring. In the case of implementations that are creating a singleton object, this method should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too. This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available. Note Autowiring will simply ignore FactoryBeans that return
| |
| isSingleton | back to summary |
|---|---|
| public boolean isSingleton() Overrides default org. Doc from org. Is the object managed by this factory a singleton? That is,
will Note If a FactoryBean indicates to hold a singleton object,
the object returned from The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there. Note This method returning The default implementation returns
| |
| setDefaultContentType | back to summary |
|---|---|
| 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 | back to summary |
|---|---|
| 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 | back to summary |
|---|---|
| public void setDefaultContentTypeStrategy(ContentNegotiationStrategy strategy) Set a custom By default this is not set.
| |
| setFavorParameter | back to summary |
|---|---|
| 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 By default this is set to
| |
| setFavorPathExtension | back to summary |
|---|---|
| public void setFavorPathExtension(boolean favorPathExtension)
Deprecated as of 5.2.4. See class-level note on the deprecation of path
extension config options. As there is no replacement for this method,
in 5.2.x it is necessary to set it to Whether the path extension in the URL path should be used to determine the requested media type. By default this is set to
| |
| setIgnoreAcceptHeader | back to summary |
|---|---|
| public void setIgnoreAcceptHeader(boolean ignoreAcceptHeader) Whether to disable checking the 'Accept' request header. By default this value is set to | |
| setIgnoreUnknownPathExtensions | back to summary |
|---|---|
| public void setIgnoreUnknownPathExtensions(boolean ignore)
Deprecated as of 5.2.4. See class-level note on the deprecation of path extension config options. Whether to ignore requests with path extension that cannot be resolved
to any media type. Setting this to By default this is set to
| |
| setMediaTypes | back to summary |
|---|---|
| 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 Note: Mappings registered here may be accessed via
| |
| setParameterName | back to summary |
|---|---|
| public void setParameterName(String parameterName) Set the query parameter name to use when The default parameter name is | |
| setServletContext | back to summary |
|---|---|
| public void setServletContext(ServletContext servletContext) Implements org. Invoked by Spring to inject the ServletContext.
| |
| setStrategies | back to summary |
|---|---|
| public void setStrategies(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.
| |
| setUseJaf | back to summary |
|---|---|
| public void setUseJaf(boolean useJaf)
Deprecated as of 5.0, in favor of Indicate whether to use the Java Activation Framework as a fallback option to map from file extensions to media types.
| |
| setUseRegisteredExtensionsOnly | back to summary |
|---|---|
| public void setUseRegisteredExtensionsOnly(boolean useRegisteredExtensionsOnly) When By default this is not set in which case dynamic resolution is on. | |
| useRegisteredExtensionsOnly | back to summary |
|---|---|
| private boolean useRegisteredExtensionsOnly() | |