Fix annotation lookup on proxied EndpointExtension
See gh-17807
This commit is contained in:
committed by
Stephane Nicoll
parent
5216574fc9
commit
9083da2876
@@ -469,8 +469,8 @@ public abstract class EndpointDiscoverer<E extends ExposableEndpoint<O>, O exten
|
|||||||
ExtensionBean(String beanName, Object bean) {
|
ExtensionBean(String beanName, Object bean) {
|
||||||
this.bean = bean;
|
this.bean = bean;
|
||||||
this.beanName = beanName;
|
this.beanName = beanName;
|
||||||
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(bean.getClass(),
|
AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(bean.getClass(),
|
||||||
EndpointExtension.class);
|
EndpointExtension.class, false, true);
|
||||||
Class<?> endpointType = attributes.getClass("endpoint");
|
Class<?> endpointType = attributes.getClass("endpoint");
|
||||||
AnnotationAttributes endpointAttributes = AnnotatedElementUtils.findMergedAnnotationAttributes(endpointType,
|
AnnotationAttributes endpointAttributes = AnnotatedElementUtils.findMergedAnnotationAttributes(endpointType,
|
||||||
Endpoint.class, true, true);
|
Endpoint.class, true, true);
|
||||||
|
|||||||
@@ -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.invoke.convert.ConversionServiceParameterValueMapper;
|
||||||
import org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker;
|
import org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker;
|
||||||
import org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor;
|
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.ApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -112,6 +114,15 @@ public class EndpointDiscovererTests {
|
|||||||
load(TestEndpointConfiguration.class, this::hasTestEndpoint);
|
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
|
@Test
|
||||||
public void getEndpointsWhenHasEndpointInParentContextShouldReturnEndpoint() {
|
public void getEndpointsWhenHasEndpointInParentContextShouldReturnEndpoint() {
|
||||||
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(
|
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
|
@Configuration
|
||||||
static class TestEndpointConfiguration {
|
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 })
|
@Import({ TestEndpoint.class, SpecializedTestEndpoint.class, SpecializedExtension.class })
|
||||||
static class SpecializedEndpointsConfiguration {
|
static class SpecializedEndpointsConfiguration {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user