mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
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
This commit is contained in:
parent
cb76502a44
commit
ed50bf2494
@ -423,8 +423,8 @@ public abstract class EndpointDiscoverer<E extends ExposableEndpoint<O>, O exten
|
||||
}
|
||||
|
||||
private Class<?> getFilter(Class<?> type) {
|
||||
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(type,
|
||||
FilteredEndpoint.class);
|
||||
AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(type,
|
||||
FilteredEndpoint.class, false, true);
|
||||
if (attributes == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -209,7 +209,8 @@ public class EndpointDiscovererTests {
|
||||
load(SpecializedEndpointsConfiguration.class, (context) -> {
|
||||
SpecializedEndpointDiscoverer discoverer = new SpecializedEndpointDiscoverer(context);
|
||||
Map<EndpointId, SpecializedExposableEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"), EndpointId.of("specialized"));
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"), EndpointId.of("specialized"),
|
||||
EndpointId.of("specialized-superclass"));
|
||||
});
|
||||
}
|
||||
|
||||
@ -252,7 +253,7 @@ public class EndpointDiscovererTests {
|
||||
load(SpecializedEndpointsConfiguration.class, (context) -> {
|
||||
EndpointFilter<SpecializedExposableEndpoint> filter = (endpoint) -> {
|
||||
EndpointId id = endpoint.getEndpointId();
|
||||
return !id.equals(EndpointId.of("specialized"));
|
||||
return !id.equals(EndpointId.of("specialized")) && !id.equals(EndpointId.of("specialized-superclass"));
|
||||
};
|
||||
SpecializedEndpointDiscoverer discoverer = new SpecializedEndpointDiscoverer(context,
|
||||
Collections.singleton(filter));
|
||||
@ -401,7 +402,8 @@ public class EndpointDiscovererTests {
|
||||
|
||||
}
|
||||
|
||||
@Import({ TestEndpoint.class, SpecializedTestEndpoint.class, SpecializedExtension.class })
|
||||
@Import({ TestEndpoint.class, SpecializedTestEndpoint.class, SpecializedSuperclassTestEndpoint.class,
|
||||
SpecializedExtension.class })
|
||||
static class SpecializedEndpointsConfiguration {
|
||||
|
||||
}
|
||||
@ -494,6 +496,20 @@ public class EndpointDiscovererTests {
|
||||
|
||||
}
|
||||
|
||||
@SpecializedEndpoint(id = "specialized-superclass")
|
||||
static class AbstractFilteredEndpoint {
|
||||
|
||||
}
|
||||
|
||||
static class SpecializedSuperclassTestEndpoint extends AbstractFilteredEndpoint {
|
||||
|
||||
@ReadOperation
|
||||
public Object getAll() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class SubSpecializedTestEndpoint extends SpecializedTestEndpoint {
|
||||
|
||||
@ReadOperation
|
||||
|
Loading…
Reference in New Issue
Block a user