diff --git a/spring-boot-actuator-docs/pom.xml b/spring-boot-actuator-docs/pom.xml index 6b0c86cabc8..b7dc435d3cc 100644 --- a/spring-boot-actuator-docs/pom.xml +++ b/spring-boot-actuator-docs/pom.xml @@ -44,6 +44,11 @@ h2 provided + + com.jayway.jsonpath + json-path + provided + junit junit @@ -81,6 +86,12 @@ org.springframework.hateoas spring-hateoas + provided + + + org.springframework.plugin + spring-plugin-core + provided org.springframework.restdocs diff --git a/spring-boot-actuator-docs/src/main/asciidoc/index.adoc b/spring-boot-actuator-docs/src/main/asciidoc/index.adoc index 0dc1aa09bcd..cec828cf48b 100644 --- a/spring-boot-actuator-docs/src/main/asciidoc/index.adoc +++ b/spring-boot-actuator-docs/src/main/asciidoc/index.adoc @@ -57,13 +57,15 @@ HAL browser is not active). == Hypermedia Support -If https://projects.spring.io/spring-hateoas[Spring HATEOAS] is enabled (i.e. if it is -on the classpath by default) then the Actuator endpoint responses are enhanced with -hypermedia in the form of "links". The default media type for responses is -http://stateless.co/hal_specification.html[HAL], resulting in each resource having an -extra property called "_links". You can change the media type to another one supported by -Spring HATEOAS by providing your own `@EnableHypermedia` annotation and custom providers -as necessary. +If `endpoints.hypermedia.enabled` is set to `true` and +https://projects.spring.io/spring-hateoas[Spring HATEOAS] is on the classpath (e.g. +through the `spring-boot-starter-hateoas` or if you are using +http://projects.spring.io/spring-data-rest[Spring Data REST]) then the Actuator endpoint +responses are enhanced with hypermedia in the form of "links". The default media type for +responses is http://stateless.co/hal_specification.html[HAL], resulting in each resource +having an extra property called "_links". You can change the media type to another one +supported by Spring HATEOAS by providing your own `@EnableHypermedia` annotation and +custom providers as necessary. Example enhanced "/metrics" endpoint with additional "_links": diff --git a/spring-boot-actuator-docs/src/restdoc/java/org/springframework/boot/actuate/hypermedia/HypermediaEndpointDocumentation.java b/spring-boot-actuator-docs/src/restdoc/java/org/springframework/boot/actuate/hypermedia/HypermediaEndpointDocumentation.java index 4c2b7a43e7f..00b6e7852d9 100644 --- a/spring-boot-actuator-docs/src/restdoc/java/org/springframework/boot/actuate/hypermedia/HypermediaEndpointDocumentation.java +++ b/spring-boot-actuator-docs/src/restdoc/java/org/springframework/boot/actuate/hypermedia/HypermediaEndpointDocumentation.java @@ -33,12 +33,14 @@ import org.springframework.test.web.servlet.MockMvc; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringRunner.class) @ContextConfiguration(classes = SpringBootHypermediaApplication.class, loader = SpringBootContextLoader.class) @WebAppConfiguration -@TestPropertySource(properties = "spring.jackson.serialization.indent_output=true") +@TestPropertySource(properties = { "spring.jackson.serialization.indent_output=true", + "endpoints.hypermedia.enabled=true" }) @DirtiesContext @AutoConfigureMockMvc @AutoConfigureRestDocs("target/generated-snippets") @@ -56,7 +58,10 @@ public class HypermediaEndpointDocumentation { @Test public void metrics() throws Exception { this.mockMvc.perform(get("/metrics").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()).andDo(document("metrics/hypermedia")); + .andExpect(status().isOk()) + .andExpect(jsonPath("$._links.self.href") + .value("http://localhost:8080/metrics")) + .andDo(document("metrics/hypermedia")); } @Test diff --git a/spring-boot-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 8ce47a4b0bc..c9a68e36517 100644 --- a/spring-boot-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -47,6 +47,12 @@ "vcap_services" ] }, + { + "name": "endpoints.hypermedia.enabled", + "type": "java.lang.Boolean", + "description": "Enable hypermedia support for endpoints.", + "defaultValue": false + }, { "name": "endpoints.info.path", "type": "java.lang.String", diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 3d035e5413a..9e982f6e619 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -946,6 +946,7 @@ content into your application; rather pick only the properties that you need. endpoints.heapdump.enabled= # Enable the endpoint. endpoints.heapdump.path= # Endpoint path. endpoints.heapdump.sensitive= # Mark if the endpoint exposes sensitive information. + endpoints.hypermedia.enabled=false # Enable hypermedia support for endpoints. endpoints.info.enabled= # Enable the endpoint. endpoints.info.id= # Endpoint identifier. endpoints.info.path= # Endpoint path. diff --git a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index 5e47bb167c5..8f2c11e7042 100644 --- a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -203,7 +203,8 @@ For example, to mark _all_ endpoints as sensitive except `info`: [[production-ready-endpoint-hypermedia]] === Hypermedia for actuator MVC endpoints -If http://projects.spring.io/spring-hateoas[Spring HATEOAS] is on the classpath (e.g. +If `endpoints.hypermedia.enabled` is set to `true` and +http://projects.spring.io/spring-hateoas[Spring HATEOAS] is on the classpath (e.g. through the `spring-boot-starter-hateoas` or if you are using http://projects.spring.io/spring-data-rest[Spring Data REST]) then the HTTP endpoints from the Actuator are enhanced with hypermedia links, and a "`discovery page`" is added