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
EntityModelandCollectionModelin the hypermedia specific format. -
If JSONPath is on the classpath, it automatically registers a
LinkDiscovererinstance to look up links by theirrelin plain JSON representations (see UsingLinkDiscovererInstances). -
By default, it enables entity links and automatically picks up
EntityLinksimplementations and bundles them into aDelegatingEntityLinksinstance that you can autowire. -
It automatically picks up all
RelProviderimplementations in theApplicationContextand bundles them into aDelegatingRelProviderthat you can autowire. It registers providers to consider@Relationon domain types as well as Spring MVC controllers. If the EVO inflector is on the classpath, collectionrelvalues 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 { … }