From b92bb9332ba6527558625a569973cac7736b1a8d Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 10 Feb 2021 15:55:29 +0100 Subject: [PATCH] Polish "Filter properties with a particular prefix" See gh-24718 --- .../src/docs/asciidoc/endpoints/configprops.adoc | 11 +++++++---- ...onPropertiesReportEndpointAutoConfiguration.java | 2 +- ...nPropertiesReportEndpointDocumentationTests.java | 2 +- .../ConfigurationPropertiesReportEndpoint.java | 8 +++----- ...urationPropertiesReportEndpointWebExtension.java | 11 ++++++----- ...ationPropertiesReportEndpointFilteringTests.java | 13 ++++++++----- ...PropertiesReportEndpointWebIntegrationTests.java | 2 +- 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/asciidoc/endpoints/configprops.adoc b/spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/asciidoc/endpoints/configprops.adoc index a60f4c72e0..7bb24d9ce7 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/asciidoc/endpoints/configprops.adoc +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/asciidoc/endpoints/configprops.adoc @@ -25,13 +25,14 @@ The response contains details of the application's `@ConfigurationProperties` be The following table describes the structure of the response: [cols="2,1,3"] -include::{snippets}/configprops/response-fields.adoc[] +include::{snippets}/configprops/all/response-fields.adoc[] + [[configprops-retrieving-by-prefix]] == Retrieving @ConfigurationProperties Beans By Prefix -To retrieve the `@ConfigurationProperties` beans mapped under a certain prefix, make a `GET` request to `/actuator/configprops/{prefix}`, as shown in the following curl-based example: +To retrieve the `@ConfigurationProperties` beans mapped under a certain prefix, make a `GET` request to `/actuator/configprops/\{prefix}`, as shown in the following curl-based example: include::{snippets}/configprops/prefixed/curl-request.adoc[] @@ -39,7 +40,9 @@ The resulting response is similar to the following: include::{snippets}/configprops/prefixed/http-response.adoc[] -NOTE: The `{prefix}` does not need to be exact, a more general prefix will return all beans mapped under that prefix stem. +NOTE: The `\{prefix}` does not need to be exact, a more general prefix will return all beans mapped under that prefix stem. + + [[configprops-retrieving-by-prefix-response-structure]] === Response Structure @@ -48,4 +51,4 @@ The response contains details of the application's `@ConfigurationProperties` be The following table describes the structure of the response: [cols="2,1,3"] -include::{snippets}/configprops/prefixed/response-fields.adoc[] \ No newline at end of file +include::{snippets}/configprops/prefixed/response-fields.adoc[] diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java index 8d1217a6cc..9c9b938514 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/ConfigurationPropertiesReportEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/ConfigurationPropertiesReportEndpointDocumentationTests.java index e8a351ab41..fa7dc514e9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/ConfigurationPropertiesReportEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/ConfigurationPropertiesReportEndpointDocumentationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java index 6e83badf13..b7be20f55e 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java @@ -121,7 +121,7 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext } @ReadOperation - public ApplicationConfigurationProperties configurationProperties(@Selector String prefix) { + public ApplicationConfigurationProperties configurationPropertiesWithPrefix(@Selector String prefix) { return extract(this.context, (bean) -> bean.getAnnotation().prefix().startsWith(prefix)); } @@ -181,11 +181,9 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext private ContextConfigurationProperties describeBeans(ObjectMapper mapper, ApplicationContext context, Predicate beanFilterPredicate) { Map beans = ConfigurationPropertiesBean.getAll(context); - Map descriptors = beans.values().stream() - .filter(beanFilterPredicate::test) - .collect(Collectors.toMap((bean) -> bean.getName(), (bean) -> describeBean(mapper, bean))); - + .filter(beanFilterPredicate) + .collect(Collectors.toMap(ConfigurationPropertiesBean::getName, (bean) -> describeBean(mapper, bean))); return new ContextConfigurationProperties(descriptors, (context.getParent() != null) ? context.getParent().getId() : null); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointWebExtension.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointWebExtension.java index 198db67da6..a1b96b9076 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointWebExtension.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointWebExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.boot.actuate.context.properties; import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties; -import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.annotation.Selector; import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse; @@ -40,10 +39,12 @@ public class ConfigurationPropertiesReportEndpointWebExtension { } @ReadOperation - public WebEndpointResponse configurationProperties(@Selector String prefix) { - ApplicationConfigurationProperties configurationProperties = this.delegate.configurationProperties(prefix); + public WebEndpointResponse configurationPropertiesWithPrefix( + @Selector String prefix) { + ApplicationConfigurationProperties configurationProperties = this.delegate + .configurationPropertiesWithPrefix(prefix); boolean foundMatchingBeans = configurationProperties.getContexts().values().stream() - .map(ContextConfigurationProperties::getBeans).anyMatch((beans) -> !beans.isEmpty()); + .anyMatch((context) -> !context.getBeans().isEmpty()); return (foundMatchingBeans) ? new WebEndpointResponse<>(configurationProperties, WebEndpointResponse.STATUS_OK) : new WebEndpointResponse<>(WebEndpointResponse.STATUS_NOT_FOUND); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointFilteringTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointFilteringTests.java index 7c7728f81c..ec2f5c7a0b 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointFilteringTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointFilteringTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,10 +42,11 @@ class ConfigurationPropertiesReportEndpointFilteringTests { contextRunner.run((context) -> { ConfigurationPropertiesReportEndpoint endpoint = context .getBean(ConfigurationPropertiesReportEndpoint.class); - ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties("only.bar"); + ApplicationConfigurationProperties applicationProperties = endpoint + .configurationPropertiesWithPrefix("only.bar"); assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId()); ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId()); - assertThat(contextProperties.getBeans().values()).hasSize(1).first().hasFieldOrPropertyWithValue("prefix", + assertThat(contextProperties.getBeans().values()).singleElement().hasFieldOrPropertyWithValue("prefix", "only.bar"); }); } @@ -57,7 +58,8 @@ class ConfigurationPropertiesReportEndpointFilteringTests { contextRunner.run((context) -> { ConfigurationPropertiesReportEndpoint endpoint = context .getBean(ConfigurationPropertiesReportEndpoint.class); - ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties("foo."); + ApplicationConfigurationProperties applicationProperties = endpoint + .configurationPropertiesWithPrefix("foo."); assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId()); ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId()); assertThat(contextProperties.getBeans()).containsOnlyKeys("primaryFoo", "secondaryFoo"); @@ -71,7 +73,8 @@ class ConfigurationPropertiesReportEndpointFilteringTests { contextRunner.run((context) -> { ConfigurationPropertiesReportEndpoint endpoint = context .getBean(ConfigurationPropertiesReportEndpoint.class); - ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties("foo.third"); + ApplicationConfigurationProperties applicationProperties = endpoint + .configurationPropertiesWithPrefix("foo.third"); assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId()); ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId()); assertThat(contextProperties.getBeans()).isEmpty(); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointWebIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointWebIntegrationTests.java index f5b3ae2057..80b6b16da4 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointWebIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointWebIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.