Spring HATEOAS
原文:https://docs.spring.io/spring-boot/reference/web/spring-hateoas.html (Spring Boot 4.2.0)
如果你开发使用超媒体的 RESTful API,Spring Boot 提供了 Spring HATEOAS 的自动配置,它适用于大多数应用。该自动配置取代了使用 @EnableHypermediaSupport 的需要,并注册了许多 bean 以简化构建基于超媒体的应用,包括 LinkDiscoverers(用于客户端支持)和一个经过配置的 JsonMapper,用于将响应正确地编组为所需的表示形式。
JsonMapper 可以通过设置各种 spring.jackson.* 属性进行定制,或者通过 JsonMapperBuilderCustomizer bean(如果存在)进行定制。
你可以通过使用 @EnableHypermediaSupport 来控制 Spring HATEOAS 的配置。请注意,这样做会禁用前面描述的 JsonMapper 定制。
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,并定义一个 HypermediaMappingInformation 或 HalConfiguration,以根据应用及其客户端的需求配置 Spring HATEOAS。