Skip to content

Commit ed50bf2

Browse files
committed
Honour EndpointFilter configured on an endpoint's superclass
Previously, @EndpointFilter would only have an effect when used as an annotation or meta-annotation on the endpoint class itself. It would have no effect when used on a super-class of the endpoint bean's class. This commit updates EndpointDiscoverer so that an @EndpointFilter annotation or meta-annotation on a super-class will be found and applied to the discovery process. This is achieved by using find… rather than get… when retrieving the attributes for the EndpointFilter annotation. Fixes gh-17866
1 parent cb76502 commit ed50bf2

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/annotation/EndpointDiscoverer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ public Set<ExtensionBean> getExtensions() {
423423
}
424424

425425
private Class<?> getFilter(Class<?> type) {
426-
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(type,
427-
FilteredEndpoint.class);
426+
AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(type,
427+
FilteredEndpoint.class, false, true);
428428
if (attributes == null) {
429429
return null;
430430
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/annotation/EndpointDiscovererTests.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ public void getEndpointsWhenHasSpecializedFiltersInSpecializedDiscovererShouldNo
209209
load(SpecializedEndpointsConfiguration.class, (context) -> {
210210
SpecializedEndpointDiscoverer discoverer = new SpecializedEndpointDiscoverer(context);
211211
Map<EndpointId, SpecializedExposableEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
212-
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"), EndpointId.of("specialized"));
212+
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"), EndpointId.of("specialized"),
213+
EndpointId.of("specialized-superclass"));
213214
});
214215
}
215216

@@ -252,7 +253,7 @@ public void getEndpointsShouldApplyFilters() {
252253
load(SpecializedEndpointsConfiguration.class, (context) -> {
253254
EndpointFilter<SpecializedExposableEndpoint> filter = (endpoint) -> {
254255
EndpointId id = endpoint.getEndpointId();
255-
return !id.equals(EndpointId.of("specialized"));
256+
return !id.equals(EndpointId.of("specialized")) && !id.equals(EndpointId.of("specialized-superclass"));
256257
};
257258
SpecializedEndpointDiscoverer discoverer = new SpecializedEndpointDiscoverer(context,
258259
Collections.singleton(filter));
@@ -401,7 +402,8 @@ public TestEndpoint scopedTargetTestEndpoint() {
401402

402403
}
403404

404-
@Import({ TestEndpoint.class, SpecializedTestEndpoint.class, SpecializedExtension.class })
405+
@Import({ TestEndpoint.class, SpecializedTestEndpoint.class, SpecializedSuperclassTestEndpoint.class,
406+
SpecializedExtension.class })
405407
static class SpecializedEndpointsConfiguration {
406408

407409
}
@@ -494,6 +496,20 @@ public Object getAll() {
494496

495497
}
496498

499+
@SpecializedEndpoint(id = "specialized-superclass")
500+
static class AbstractFilteredEndpoint {
501+
502+
}
503+
504+
static class SpecializedSuperclassTestEndpoint extends AbstractFilteredEndpoint {
505+
506+
@ReadOperation
507+
public Object getAll() {
508+
return null;
509+
}
510+
511+
}
512+
497513
static class SubSpecializedTestEndpoint extends SpecializedTestEndpoint {
498514

499515
@ReadOperation

0 commit comments

Comments
 (0)