Class RepositoryRestConfiguration
java.lang.Object
org.springframework.data.rest.core.config.RepositoryRestConfiguration
Spring Data REST configuration options.
- Author:
- Jon Brisbin, Oliver Gierke, Jeremy Rickard, Greg Turnquist, Mark Paluch
-
Constructor Summary
ConstructorDescriptionRepositoryRestConfiguration
(ProjectionDefinitionConfiguration projectionConfiguration, MetadataConfiguration metadataConfiguration, EnumTranslationConfiguration enumTranslationConfiguration) Creates a newRepositoryRestConfiguration
with the givenProjectionDefinitionConfiguration
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Disables the default exposure of repositories entirely.exposeIdsFor
(Class<?>... domainTypes) Set the list of domain types for which we will expose the ID value as a normal property.boolean
Returns whether to expose repository methods by default.Deprecated.for removal in 3.5The base path to expose repository resources under.Deprecated.usegetBasePath()
instead.Get theMediaType
to use as a default when none is specified.int
Get the default size ofPageable
s.Deprecated.for removal in 3.5List<EntityLookup<?>>
getEntityLookups
(Repositories repositories) Returns allEntityLookup
s considering the customizations made to the configuration.Returns theEnumTranslationConfiguration
to be used.Get the name of the URL query string parameter that indicates how many results to return at once.org.springframework.hateoas.server.LinkRelationProvider
Returns theLinkRelationProvider
configured to calculate the link relation defaults for repositories.int
Get the maximum size of pages.Returns theMetadataConfiguration
to customize metadata exposure.Get the name of the URL query string parameter that indicates what page to return.Returns theProjectionDefinitionConfiguration
to register addition projections.org.springframework.hateoas.server.LinkRelationProvider
Deprecated.since 3.5, usegetLinkRelationProvider()
instead.Returns theRepositoryDetectionStrategy
to be used to decide which repositories get exposed.getResourceMappingForDomainType
(Class<?> domainType) Deprecated.for removal in 3.5getResourceMappingForRepository
(Class<?> repositoryInterface) Deprecated.for removal in 3.5Get the name of the URL query string parameter that indicates what direction to sort results.boolean
hasResourceMappingForDomainType
(Class<?> domainType) Deprecated.for removal in 3.5boolean
hasResourceMappingForRepository
(Class<?> repositoryInterface) Deprecated.for removal in 3.5boolean
Returns whether enum value translation is enabled.boolean
isIdExposedFor
(Class<?> domainType) Should we expose the ID property for this domain type?boolean
isLookupType
(Class<?> type) Deprecated.Deprecated.Deprecated.since 2.4, usegetMetadataConfiguration()
instead.Deprecated.since 2.4, usegetProjectionConfiguration()
instead.boolean
returnBodyOnCreate
(String acceptHeader) Whether to return a response body after creating an entity considering the given accept header.boolean
returnBodyOnDelete
(String acceptHeader) Whether to return a response body after deleting an entity considering the given accept header.boolean
returnBodyOnUpdate
(String acceptHeader) Whether to return a response body after updating an entity considering the given accept header.setBasePath
(String basePath) Configures the base path to be used by Spring Data REST to expose repository resources.setDefaultMediaType
(MediaType defaultMediaType) Set theMediaType
to use as a default when none is specified.setDefaultPageSize
(int defaultPageSize) Set the default size ofPageable
s.setEnableEnumTranslation
(boolean enableEnumTranslation) Configures whether to enable enum value translation via the Spring Data REST default resource bundle.void
setExposeRepositoryMethodsByDefault
(boolean exposeRepositoryMethodsByDefault) Sets whether to expose repository methods by default.setLimitParamName
(String limitParamName) Set the name of the URL query string parameter that indicates how many results to return at once.setLinkRelationProvider
(org.springframework.hateoas.server.LinkRelationProvider provider) Configures theLinkRelationProvider
to be used to calculate theLinkRelation
defaults for repositories.setMaxPageSize
(int maxPageSize) Set the maximum size of pages.setPageParamName
(String pageParamName) Set the name of the URL query string parameter that indicates what page to return.void
setRelProvider
(org.springframework.hateoas.server.LinkRelationProvider relProvider) Deprecated.since 3.5, usesetLinkRelationProvider(LinkRelationProvider)
instead.setRepositoryDetectionStrategy
(RepositoryDetectionStrategy repositoryDetectionStrategy) Configures theRepositoryDetectionStrategy
to be used to determine which repositories get exposed.setResourceMappingForDomainType
(Class<?> domainType) Deprecated.for removal in 3.5setResourceMappingForRepository
(Class<?> repositoryInterface) Deprecated.for removal in 3.5setReturnBodyForPutAndPost
(Boolean returnBody) Convenience method to activate returning response bodies for allPUT
andPOST
requests, i.e. both creating and updating entities.setReturnBodyOnCreate
(Boolean returnBody) Set whether to return a response body after creating an entity.setReturnBodyOnDelete
(Boolean returnBodyOnDelete) Set whether to return a response body after deleting an entity.setReturnBodyOnUpdate
(Boolean returnBodyOnUpdate) Set whether to return a response body after updating an entity.setSortParamName
(String sortParamName) Set the name of the URL query string parameter that indicates what direction to sort results.boolean
Returns whether HAL will be served as primary representation in case onapplication/json
is requested.useHalAsDefaultJsonMediaType
(boolean useHalAsDefaultJsonMediaType) Configures whether HAL will be served as primary representation in case onapplication/json
is requested.Returns theEntityLookupRegistrar
to create customEntityLookup
instances registered in the configuration.
-
Constructor Details
-
RepositoryRestConfiguration
public RepositoryRestConfiguration(ProjectionDefinitionConfiguration projectionConfiguration, MetadataConfiguration metadataConfiguration, EnumTranslationConfiguration enumTranslationConfiguration) Creates a newRepositoryRestConfiguration
with the givenProjectionDefinitionConfiguration
.- Parameters:
projectionConfiguration
- must not be null.metadataConfiguration
- must not be null.enumTranslationConfiguration
- must not be null.
-
-
Method Details
-
getBaseUri
Deprecated.usegetBasePath()
instead.The base URI against which the exporter should calculate its links.- Returns:
- The base URI.
-
getBasePath
The base path to expose repository resources under.- Returns:
- the basePath
-
setBasePath
Configures the base path to be used by Spring Data REST to expose repository resources.- Parameters:
basePath
- the basePath to set
-
getDefaultPageSize
public int getDefaultPageSize()Get the default size ofPageable
s. Default is 20.- Returns:
- The default page size.
-
setDefaultPageSize
Set the default size ofPageable
s.- Parameters:
defaultPageSize
- The default page size.- Returns:
- this
-
getMaxPageSize
public int getMaxPageSize()Get the maximum size of pages.- Returns:
- Maximum page size.
-
setMaxPageSize
Set the maximum size of pages.- Parameters:
maxPageSize
- Maximum page size.- Returns:
- this
-
getPageParamName
Get the name of the URL query string parameter that indicates what page to return. Default is 'page'.- Returns:
- Name of the query parameter used to indicate the page number to return.
-
setPageParamName
Set the name of the URL query string parameter that indicates what page to return.- Parameters:
pageParamName
- Name of the query parameter used to indicate the page number to return.- Returns:
- this
-
getLimitParamName
Get the name of the URL query string parameter that indicates how many results to return at once. Default is 'limit'.- Returns:
- Name of the query parameter used to indicate the maximum number of entries to return at a time.
-
setLimitParamName
Set the name of the URL query string parameter that indicates how many results to return at once.- Parameters:
limitParamName
- Name of the query parameter used to indicate the maximum number of entries to return at a time.- Returns:
- this
-
getSortParamName
Get the name of the URL query string parameter that indicates what direction to sort results. Default is 'sort'.- Returns:
- Name of the query string parameter used to indicate what field to sort on.
-
setSortParamName
Set the name of the URL query string parameter that indicates what direction to sort results.- Parameters:
sortParamName
- Name of the query string parameter used to indicate what field to sort on.- Returns:
- this
-
getDefaultMediaType
Get theMediaType
to use as a default when none is specified.- Returns:
- Default content type if none has been specified.
-
setDefaultMediaType
Set theMediaType
to use as a default when none is specified.- Parameters:
defaultMediaType
- default content type if none has been specified.- Returns:
- this
-
useHalAsDefaultJsonMediaType
public boolean useHalAsDefaultJsonMediaType()Returns whether HAL will be served as primary representation in case onapplication/json
is requested. This defaults to true. If configured to false the legacy Spring Data representation will be rendered.- Returns:
-
useHalAsDefaultJsonMediaType
public RepositoryRestConfiguration useHalAsDefaultJsonMediaType(boolean useHalAsDefaultJsonMediaType) Configures whether HAL will be served as primary representation in case onapplication/json
is requested. This defaults to true. If configured to false the legacy Spring Data representation will be rendered.- Parameters:
useHalAsDefaultJsonMediaType
-- Returns:
-
setReturnBodyForPutAndPost
Convenience method to activate returning response bodies for allPUT
andPOST
requests, i.e. both creating and updating entities.- Parameters:
returnBody
- can be null, expressing the decision shall be derived from the presence of anAccept
header in the request.- Returns:
-
isReturnBodyOnCreate
Deprecated.Whether to return a response body after creating an entity.- Returns:
Boolean.TRUE
to enforce returning a body on create,Boolean.FALSE
otherwise. If null and anAccept
header present in the request will cause a body being returned. If theAccept
header is not present, no body will be rendered.
-
returnBodyOnCreate
Whether to return a response body after creating an entity considering the given accept header.- Parameters:
acceptHeader
- can be null or empty.- Returns:
-
setReturnBodyOnCreate
Set whether to return a response body after creating an entity.- Parameters:
returnBody
- can be null, expressing the decision shall be derived from the presence of anAccept
header in the request.- Returns:
- this
-
isReturnBodyOnUpdate
Deprecated.Whether to return a response body after updating an entity.- Returns:
Boolean.TRUE
to enforce returning a body on create,Boolean.FALSE
otherwise. If null and anAccept
header present in the request will cause a body being returned. If theAccept
header is not present, no body will be rendered.
-
returnBodyOnUpdate
Whether to return a response body after updating an entity considering the given accept header.- Parameters:
acceptHeader
- can be null or empty.- Returns:
-
setReturnBodyOnUpdate
Set whether to return a response body after updating an entity.- Parameters:
returnBodyOnUpdate
- can be null, expressing the decision shall be derived from the presence of anAccept
header in the request.- Returns:
- this
-
returnBodyOnDelete
Whether to return a response body after deleting an entity considering the given accept header.- Parameters:
acceptHeader
- can be null or empty.- Returns:
- Since:
- 4.1
-
setReturnBodyOnDelete
Set whether to return a response body after deleting an entity.- Parameters:
returnBodyOnDelete
- can be null, expressing the decision shall be derived from the presence of anAccept
header in the request.- Returns:
- this
- Since:
- 4.1
-
setResourceMappingForDomainType
Deprecated.for removal in 3.5Start configuration aResourceMapping
for a specific domain type.- Parameters:
domainType
- TheClass
of the domain type to configure a mapping for.- Returns:
- A new
ResourceMapping
for configuring how a domain type is mapped.
-
getResourceMappingForDomainType
Deprecated.for removal in 3.5Get theResourceMapping
for a specific domain type.- Parameters:
domainType
- TheClass
of the domain type.- Returns:
- A
ResourceMapping
for that domain type or null if none exists.
-
hasResourceMappingForDomainType
Deprecated.for removal in 3.5Whether there is aResourceMapping
for the given domain type.- Parameters:
domainType
- The domain type to find aResourceMapping
for.- Returns:
- true if a
ResourceMapping
exists for this domain class, false otherwise.
-
getDomainTypesResourceMappingConfiguration
Deprecated.for removal in 3.5Get theResourceMappingConfiguration
that is currently configured.- Returns:
-
setResourceMappingForRepository
Deprecated.for removal in 3.5Start configuration aResourceMapping
for a specific repository interface.- Parameters:
repositoryInterface
- TheClass
of the repository interface to configure a mapping for.- Returns:
- A new
ResourceMapping
for configuring how a repository interface is mapped.
-
getResourceMappingForRepository
Deprecated.for removal in 3.5Get theResourceMapping
for a specific repository interface.- Parameters:
repositoryInterface
- TheClass
of the repository interface.- Returns:
- A
ResourceMapping
for that repository interface or null if none exists.
-
hasResourceMappingForRepository
Deprecated.for removal in 3.5Whether there is aResourceMapping
configured for this Repository class.- Parameters:
repositoryInterface
-- Returns:
-
findRepositoryMappingForPath
Deprecated.for removal in 3.5 -
isIdExposedFor
Should we expose the ID property for this domain type?- Parameters:
domainType
- The domain type we may need to expose the ID for.- Returns:
- true is the ID is to be exposed, false otherwise.
-
exposeIdsFor
Set the list of domain types for which we will expose the ID value as a normal property.- Parameters:
domainTypes
- Array of types to expose IDs for.- Returns:
- this
-
projectionConfiguration
Deprecated.since 2.4, usegetProjectionConfiguration()
instead.Returns theProjectionDefinitionConfiguration
to register addition projections.- Returns:
-
getProjectionConfiguration
Returns theProjectionDefinitionConfiguration
to register addition projections.- Returns:
-
metadataConfiguration
Deprecated.since 2.4, usegetMetadataConfiguration()
instead.Returns theMetadataConfiguration
to customize metadata exposure.- Returns:
-
getMetadataConfiguration
Returns theMetadataConfiguration
to customize metadata exposure.- Returns:
-
setEnableEnumTranslation
Configures whether to enable enum value translation via the Spring Data REST default resource bundle. Defaults to false for backwards compatibility reasons. Will use the fully qualified enum name as key. For further details see {code EnumTranslator}.- Parameters:
enableEnumTranslation
-- See Also:
-
isEnableEnumTranslation
public boolean isEnableEnumTranslation()Returns whether enum value translation is enabled.- Returns:
- Since:
- 2.4
-
getEnumTranslationConfiguration
Returns theEnumTranslationConfiguration
to be used.- Returns:
- must not be null.
- Since:
- 2.4
-
getRepositoryDetectionStrategy
Returns theRepositoryDetectionStrategy
to be used to decide which repositories get exposed. Will beRepositoryDetectionStrategy.RepositoryDetectionStrategies.DEFAULT
by default.- Returns:
- will never be null.
- Since:
- 2.5
- See Also:
-
setRepositoryDetectionStrategy
public RepositoryRestConfiguration setRepositoryDetectionStrategy(RepositoryDetectionStrategy repositoryDetectionStrategy) Configures theRepositoryDetectionStrategy
to be used to determine which repositories get exposed. Defaults toRepositoryDetectionStrategy.RepositoryDetectionStrategies.DEFAULT
.- Parameters:
repositoryDetectionStrategy
- can be null.- Since:
- 2.5
-
exposeRepositoryMethodsByDefault
public boolean exposeRepositoryMethodsByDefault()Returns whether to expose repository methods by default.- Since:
- 3.1
- See Also:
-
setExposeRepositoryMethodsByDefault
public void setExposeRepositoryMethodsByDefault(boolean exposeRepositoryMethodsByDefault) Sets whether to expose repository methods by default. If this is disabled, CRUD methods must be annotated withRestResource
explicitly to expose the default set of resources (opt-in). If this is set to true (default), repository methods methods are exposed unless explictly annotated withRestResource
andRestResource.exported()
set to false.- Since:
- 3.1
- See Also:
-
disableDefaultExposure
public void disableDefaultExposure()Disables the default exposure of repositories entirely. I.e. repositories to be exported must now be explicitly annotated withRepositoryRestResource
and methods need to be annotated withRestResource
to trigger exposure of default resources. Basically a shortcut for calling bothsetRepositoryDetectionStrategy(RepositoryDetectionStrategy)
toRepositoryDetectionStrategy.RepositoryDetectionStrategies.ANNOTATED
and settingsetExposeRepositoryMethodsByDefault(boolean)
to false. -
withEntityLookup
Returns theEntityLookupRegistrar
to create customEntityLookup
instances registered in the configuration.- Returns:
- the
EntityLookupRegistrar
to build customEntityLookup
s. - Since:
- 2.5
-
getEntityLookups
Returns allEntityLookup
s considering the customizations made to the configuration.- Parameters:
repositories
- must not be null.- Returns:
-
isLookupType
-
getRelProvider
Deprecated.since 3.5, usegetLinkRelationProvider()
instead.TheLinkRelationProvider
to be used to calculate the link relation defaults for repositories. -
setRelProvider
@Deprecated public void setRelProvider(org.springframework.hateoas.server.LinkRelationProvider relProvider) Deprecated.since 3.5, usesetLinkRelationProvider(LinkRelationProvider)
instead.TheLinkRelationProvider
to be used to calculate the link relation defaults for repositories. -
getLinkRelationProvider
public org.springframework.hateoas.server.LinkRelationProvider getLinkRelationProvider()Returns theLinkRelationProvider
configured to calculate the link relation defaults for repositories. Defaults to a delegating wrapper around anAnnotationLinkRelationProvider
andEvoInflectorLinkRelationProvider
.- Returns:
- Since:
- 3.5
- See Also:
-
setLinkRelationProvider(LinkRelationProvider)
AnnotationLinkRelationProvider
EvoInflectorLinkRelationProvider
-
setLinkRelationProvider
public RepositoryRestConfiguration setLinkRelationProvider(org.springframework.hateoas.server.LinkRelationProvider provider) Configures theLinkRelationProvider
to be used to calculate theLinkRelation
defaults for repositories. The provided instance will replace the default setup completely. For details on the defaults and setting up a similar, delegating arrangement, seegetLinkRelationProvider()
.- Parameters:
provider
- must not be null.- Returns:
- the current instance
- Since:
- 3.5
-
getExposureConfiguration
-