Skip to content

Commit b92bb93

Browse files
committed
Polish "Filter properties with a particular prefix"
See gh-24718
1 parent ad7c69a commit b92bb93

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/asciidoc/endpoints/configprops.adoc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,24 @@ The response contains details of the application's `@ConfigurationProperties` be
2525
The following table describes the structure of the response:
2626

2727
[cols="2,1,3"]
28-
include::{snippets}/configprops/response-fields.adoc[]
28+
include::{snippets}/configprops/all/response-fields.adoc[]
29+
2930

3031

3132
[[configprops-retrieving-by-prefix]]
3233
== Retrieving @ConfigurationProperties Beans By Prefix
3334

34-
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:
35+
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:
3536

3637
include::{snippets}/configprops/prefixed/curl-request.adoc[]
3738

3839
The resulting response is similar to the following:
3940

4041
include::{snippets}/configprops/prefixed/http-response.adoc[]
4142

42-
NOTE: The `{prefix}` does not need to be exact, a more general prefix will return all beans mapped under that prefix stem.
43+
NOTE: The `\{prefix}` does not need to be exact, a more general prefix will return all beans mapped under that prefix stem.
44+
45+
4346

4447
[[configprops-retrieving-by-prefix-response-structure]]
4548
=== Response Structure
@@ -48,4 +51,4 @@ The response contains details of the application's `@ConfigurationProperties` be
4851
The following table describes the structure of the response:
4952

5053
[cols="2,1,3"]
51-
include::{snippets}/configprops/prefixed/response-fields.adoc[]
54+
include::{snippets}/configprops/prefixed/response-fields.adoc[]

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/ConfigurationPropertiesReportEndpointDocumentationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public ApplicationConfigurationProperties configurationProperties() {
121121
}
122122

123123
@ReadOperation
124-
public ApplicationConfigurationProperties configurationProperties(@Selector String prefix) {
124+
public ApplicationConfigurationProperties configurationPropertiesWithPrefix(@Selector String prefix) {
125125
return extract(this.context, (bean) -> bean.getAnnotation().prefix().startsWith(prefix));
126126
}
127127

@@ -181,11 +181,9 @@ private void applySerializationModifier(ObjectMapper mapper) {
181181
private ContextConfigurationProperties describeBeans(ObjectMapper mapper, ApplicationContext context,
182182
Predicate<ConfigurationPropertiesBean> beanFilterPredicate) {
183183
Map<String, ConfigurationPropertiesBean> beans = ConfigurationPropertiesBean.getAll(context);
184-
185184
Map<String, ConfigurationPropertiesBeanDescriptor> descriptors = beans.values().stream()
186-
.filter(beanFilterPredicate::test)
187-
.collect(Collectors.toMap((bean) -> bean.getName(), (bean) -> describeBean(mapper, bean)));
188-
185+
.filter(beanFilterPredicate)
186+
.collect(Collectors.toMap(ConfigurationPropertiesBean::getName, (bean) -> describeBean(mapper, bean)));
189187
return new ContextConfigurationProperties(descriptors,
190188
(context.getParent() != null) ? context.getParent().getId() : null);
191189
}

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointWebExtension.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.actuate.context.properties;
1818

1919
import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties;
20-
import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties;
2120
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
2221
import org.springframework.boot.actuate.endpoint.annotation.Selector;
2322
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
@@ -40,10 +39,12 @@ public ConfigurationPropertiesReportEndpointWebExtension(ConfigurationProperties
4039
}
4140

4241
@ReadOperation
43-
public WebEndpointResponse<ApplicationConfigurationProperties> configurationProperties(@Selector String prefix) {
44-
ApplicationConfigurationProperties configurationProperties = this.delegate.configurationProperties(prefix);
42+
public WebEndpointResponse<ApplicationConfigurationProperties> configurationPropertiesWithPrefix(
43+
@Selector String prefix) {
44+
ApplicationConfigurationProperties configurationProperties = this.delegate
45+
.configurationPropertiesWithPrefix(prefix);
4546
boolean foundMatchingBeans = configurationProperties.getContexts().values().stream()
46-
.map(ContextConfigurationProperties::getBeans).anyMatch((beans) -> !beans.isEmpty());
47+
.anyMatch((context) -> !context.getBeans().isEmpty());
4748
return (foundMatchingBeans) ? new WebEndpointResponse<>(configurationProperties, WebEndpointResponse.STATUS_OK)
4849
: new WebEndpointResponse<>(WebEndpointResponse.STATUS_NOT_FOUND);
4950
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointFilteringTests.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,10 +42,11 @@ void filterByPrefixSingleMatch() {
4242
contextRunner.run((context) -> {
4343
ConfigurationPropertiesReportEndpoint endpoint = context
4444
.getBean(ConfigurationPropertiesReportEndpoint.class);
45-
ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties("only.bar");
45+
ApplicationConfigurationProperties applicationProperties = endpoint
46+
.configurationPropertiesWithPrefix("only.bar");
4647
assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
4748
ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
48-
assertThat(contextProperties.getBeans().values()).hasSize(1).first().hasFieldOrPropertyWithValue("prefix",
49+
assertThat(contextProperties.getBeans().values()).singleElement().hasFieldOrPropertyWithValue("prefix",
4950
"only.bar");
5051
});
5152
}
@@ -57,7 +58,8 @@ void filterByPrefixMultipleMatches() {
5758
contextRunner.run((context) -> {
5859
ConfigurationPropertiesReportEndpoint endpoint = context
5960
.getBean(ConfigurationPropertiesReportEndpoint.class);
60-
ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties("foo.");
61+
ApplicationConfigurationProperties applicationProperties = endpoint
62+
.configurationPropertiesWithPrefix("foo.");
6163
assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
6264
ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
6365
assertThat(contextProperties.getBeans()).containsOnlyKeys("primaryFoo", "secondaryFoo");
@@ -71,7 +73,8 @@ void filterByPrefixNoMatches() {
7173
contextRunner.run((context) -> {
7274
ConfigurationPropertiesReportEndpoint endpoint = context
7375
.getBean(ConfigurationPropertiesReportEndpoint.class);
74-
ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties("foo.third");
76+
ApplicationConfigurationProperties applicationProperties = endpoint
77+
.configurationPropertiesWithPrefix("foo.third");
7578
assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
7679
ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
7780
assertThat(contextProperties.getBeans()).isEmpty();

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointWebIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)