Spring HATEOAS

如果您开发一个使用超媒体的RESTful API,Spring Boot为Spring HATEOAS提供了自动配置,这在大多数应用程序中都能正常工作。 自动配置消除了使用 @EnableHypermediaSupport 的需要,并注册了许多bean以简化基于超媒体的应用程序的构建,包括一个 LinkDiscoverers(用于客户端支持)和一个 JsonMapper,该bean被配置为正确地将响应转换为所需的表示形式。 < a t="C9">JsonMapper 通过设置各种 spring.jackson.* 属性进行自定义,或者如果存在的话,通过 JsonMapperBuilderCustomizer bean 进行自定义。spring-doc.cadn.net.cn

您可以通过使用 @EnableHypermediaSupport 来控制 Spring HATEOAS 的配置。 请注意,这样做会禁用前面所述的 JsonMapper 自定义功能。spring-doc.cadn.net.cn

spring-boot-starter-hateoas 专用于 Spring MVC,不应与 Spring WebFlux 混用。 若要在 Spring WebFlux 中使用 Spring HATEOAS,可直接添加对 org.springframework.hateoas:spring-hateoas 的依赖,并同时添加 spring-boot-starter-webflux 的依赖。

默认情况下,接受 application/json 的请求将收到 application/hal+json 响应。 要禁用此行为,请将 spring.hateoas.use-hal-as-default-json-media-type 设置为 false,并定义一个 HypermediaMappingInformationHalConfiguration,以配置 Spring HATEOAS,满足您的应用程序及其客户端的需求。spring-doc.cadn.net.cn