ContentNegotiationManager and configures it with
one or more 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 |
As of 5.0 you can set the exact strategies to use via
strategies(List).
Note
if you must use URL-based content type resolution,
the use of a query parameter is simpler and preferable to the use of a path
extension since the latter can cause issues with URI variables, path
parameters, and URI decoding. Consider setting favorPathExtension
to false or otherwise set the strategies to use explicitly via
strategies(List).
| Modifier and Type | Field and Description |
|---|---|
| private final ContentNegotiationManagerFactoryBean | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| public | ContentNegotiationConfigurer(ServletContext servletContext)
Class constructor with |
| Modifier and Type | Method and Description |
|---|---|
| protected ContentNegotiationManager | buildContentNegotiationManager()
Build a |
| public ContentNegotiationConfigurer | defaultContentType(MediaType... defaultContentTypes)
Set the default content type(s) to use when no content type is requested in order of priority. |
| public ContentNegotiationConfigurer | defaultContentTypeStrategy(ContentNegotiationStrategy defaultStrategy)
Set a custom |
| public ContentNegotiationConfigurer | favorParameter(boolean favorParameter)
Whether a request parameter ("format" by default) should be used to determine the requested media type. |
| public ContentNegotiationConfigurer | favorPathExtension(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 ContentNegotiationConfigurer | ignoreAcceptHeader(boolean ignoreAcceptHeader)
Whether to disable checking the 'Accept' request header. |
| public ContentNegotiationConfigurer | ignoreUnknownPathExtensions(boolean ignore)
Deprecated
as of 5.2.4.
Whether to ignore requests with path extension that cannot be resolved to any media type. |
| public ContentNegotiationConfigurer | |
| public ContentNegotiationConfigurer | |
| public ContentNegotiationConfigurer | |
| public ContentNegotiationConfigurer | replaceMediaTypes(Map<String, MediaType> mediaTypes)
Similar to |
| public void | strategies(List<ContentNegotiationStrategy>
the strategies to use strategies)Set the exact list of strategies to use. |
| public ContentNegotiationConfigurer | useJaf(boolean useJaf)
Deprecated
as of 5.0, in favor of
useRegisteredExtensionsOnly(boolean)
which has reverse behavior
When |
| public ContentNegotiationConfigurer | useRegisteredExtensionsOnly(boolean useRegisteredExtensionsOnly)
When |
| factory | back to summary |
|---|---|
| private final ContentNegotiationManagerFactoryBean factory | |
| mediaTypes | back to summary |
|---|---|
| private final Map<String, MediaType> mediaTypes | |
| ContentNegotiationConfigurer | back to summary |
|---|---|
| public ContentNegotiationConfigurer(ServletContext servletContext) Class constructor with | |
| buildContentNegotiationManager | back to summary |
|---|---|
| protected ContentNegotiationManager buildContentNegotiationManager() Build a
| |
| defaultContentType | back to summary |
|---|---|
| public ContentNegotiationConfigurer defaultContentType(MediaType... defaultContentTypes) Set the default content type(s) to use when no content type is requested in order of priority. If destinations are present that do not support any of the given media
types, consider appending By default this is not set.
| |
| defaultContentTypeStrategy | back to summary |
|---|---|
| public ContentNegotiationConfigurer defaultContentTypeStrategy(ContentNegotiationStrategy defaultStrategy) Set a custom By default this is not set.
| |
| favorParameter | back to summary |
|---|---|
| public ContentNegotiationConfigurer favorParameter(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
| |
| favorPathExtension | back to summary |
|---|---|
| public ContentNegotiationConfigurer favorPathExtension(boolean favorPathExtension)
Deprecated as of 5.2.4. See deprecation note on
Whether the path extension in the URL path should be used to determine the requested media type. By default this is set to
| |
| ignoreAcceptHeader | back to summary |
|---|---|
| public ContentNegotiationConfigurer ignoreAcceptHeader(boolean ignoreAcceptHeader) Whether to disable checking the 'Accept' request header. By default this value is set to | |
| ignoreUnknownPathExtensions | back to summary |
|---|---|
| public ContentNegotiationConfigurer ignoreUnknownPathExtensions(boolean ignore)
Deprecated as of 5.2.4. See deprecation note on
Whether to ignore requests with path extension that cannot be resolved
to any media type. Setting this to By default this is set to
| |
| mediaType | back to summary |
|---|---|
| public ContentNegotiationConfigurer mediaType(String extension, MediaType mediaType) Add a mapping from a key, extracted from a path extension or a query parameter, to a MediaType. This is required in order for the parameter strategy to work. Any extensions explicitly registered here are also treated as safe for the purpose of Reflected File Download attack detection (see Spring Framework reference documentation for more details on RFD attack protection). The path extension strategy will also try to use
| |
| mediaTypes | back to summary |
|---|---|
| public ContentNegotiationConfigurer mediaTypes(Map<String, MediaType> mediaTypes) An alternative to | |
| parameterName | back to summary |
|---|---|
| public ContentNegotiationConfigurer parameterName(String parameterName) Set the query parameter name to use when The default parameter name is | |
| replaceMediaTypes | back to summary |
|---|---|
| public ContentNegotiationConfigurer replaceMediaTypes(Map<String, MediaType> mediaTypes) Similar to
| |
| strategies | back to summary |
|---|---|
| public void strategies(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.
| |
| useJaf | back to summary |
|---|---|
| public ContentNegotiationConfigurer useJaf(boolean useJaf)
Deprecated as of 5.0, in favor of When
| |
| useRegisteredExtensionsOnly | back to summary |
|---|---|
| public ContentNegotiationConfigurer useRegisteredExtensionsOnly(boolean useRegisteredExtensionsOnly) When By default this is not set in which case
| |