Fix annotation lookup on proxied EndpointExtension

See gh-17807
This commit is contained in:
Jacques-Etienne Beaudet
2019-08-07 12:22:48 -04:00
committed by Stephane Nicoll
parent 5216574fc9
commit 9083da2876
2 changed files with 31 additions and 2 deletions

View File

@@ -469,8 +469,8 @@ public abstract class EndpointDiscoverer<E extends ExposableEndpoint<O>, O exten
ExtensionBean(String beanName, Object bean) {
this.bean = bean;
this.beanName = beanName;
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(bean.getClass(),
EndpointExtension.class);
AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(bean.getClass(),
EndpointExtension.class, false, true);
Class<?> endpointType = attributes.getClass("endpoint");
AnnotationAttributes endpointAttributes = AnnotatedElementUtils.findMergedAnnotationAttributes(endpointType,
Endpoint.class, true, true);

View File

@@ -44,6 +44,8 @@ import org.springframework.boot.actuate.endpoint.invoke.ParameterValueMapper;
import org.springframework.boot.actuate.endpoint.invoke.convert.ConversionServiceParameterValueMapper;
import org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker;
import org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.FixedValue;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -112,6 +114,15 @@ public class EndpointDiscovererTests {
load(TestEndpointConfiguration.class, this::hasTestEndpoint);
}
@Test
public void getEndpointsWhenHasProxiedEndpointShouldReturnEndpoint() {
load(ProxiedSpecializedEndpointsConfiguration.class, (context) -> {
SpecializedEndpointDiscoverer discoverer = new SpecializedEndpointDiscoverer(context);
Map<EndpointId, SpecializedExposableEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"), EndpointId.of("specialized"));
});
}
@Test
public void getEndpointsWhenHasEndpointInParentContextShouldReturnEndpoint() {
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(
@@ -327,6 +338,19 @@ public class EndpointDiscovererTests {
}
@Configuration
static class ProxiedSpecializedTestEndpointConfiguration {
@Bean
public SpecializedExtension specializedExtension() {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(SpecializedExtension.class);
enhancer.setCallback((FixedValue) () -> null);
return (SpecializedExtension) enhancer.create();
}
}
@Configuration
static class TestEndpointConfiguration {
@@ -377,6 +401,11 @@ public class EndpointDiscovererTests {
}
@Import({ TestEndpoint.class, ProxiedSpecializedTestEndpointConfiguration.class, SpecializedTestEndpoint.class })
static class ProxiedSpecializedEndpointsConfiguration {
}
@Import({ TestEndpoint.class, SpecializedTestEndpoint.class, SpecializedExtension.class })
static class SpecializedEndpointsConfiguration {