5. Configuration
This section describes how to configure Spring HATEOAS.
5.1. Using @EnableHypermediaSupport
To let the RepresentationModel
subtypes be rendered according to the specification of various hypermedia representation types, you can activate support for a particular hypermedia representation format through @EnableHypermediaSupport
. The annotation takes a HypermediaType
enumeration as its argument. Currently, we support HAL as well as a default rendering. Using the annotation triggers the following:
-
It registers necessary Jackson modules to render
EntityModel
andCollectionModel
in the hypermedia specific format. -
If JSONPath is on the classpath, it automatically registers a
LinkDiscoverer
instance to look up links by theirrel
in plain JSON representations (see UsingLinkDiscoverer
Instances). -
By default, it enables entity links and automatically picks up
EntityLinks
implementations and bundles them into aDelegatingEntityLinks
instance that you can autowire. -
It automatically picks up all
RelProvider
implementations in theApplicationContext
and bundles them into aDelegatingRelProvider
that you can autowire. It registers providers to consider@Relation
on domain types as well as Spring MVC controllers. If the EVO inflector is on the classpath, collectionrel
values are derived by using the pluralizing algorithm implemented in the library (see [spis.rel-provider]).
5.1.1. Explicitly enabling support for dedicated web stacks
By default, @EnableHypermediaSupport
will reflectively detect the web application stack you’re using and hook into the Spring components registered for those to enable support for hypermedia representations.
However, there are situations in which you’d only explicitly want to activate support for a particular stack.
E.g. if your Spring WebMVC based application uses WebFlux' WebClient
to make outgoing requests and that one is not supposed to work with hypermedia elements, you can restrict the functionality to be enabled by explicitly declaring WebMVC in the configuration:
@EnableHypermediaSupport(…, stacks = WebStack.WEBMVC)
class MyHypermediaConfiguration { … }