Skip to content

Commit b31c336

Browse files
committed
Merge pull request #17807 from jebeaudet
* pr/17807: Polish "Fix annotation lookup on proxied EndpointExtension" Fix annotation lookup on proxied EndpointExtension Closes gh-17807
2 parents 5216574 + 994f08d commit b31c336

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
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
@@ -469,8 +469,8 @@ private static class ExtensionBean {
469469
ExtensionBean(String beanName, Object bean) {
470470
this.bean = bean;
471471
this.beanName = beanName;
472-
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(bean.getClass(),
473-
EndpointExtension.class);
472+
AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(bean.getClass(),
473+
EndpointExtension.class, false, true);
474474
Class<?> endpointType = attributes.getClass("endpoint");
475475
AnnotationAttributes endpointAttributes = AnnotatedElementUtils.findMergedAnnotationAttributes(endpointType,
476476
Endpoint.class, true, true);

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import org.springframework.boot.actuate.endpoint.invoke.convert.ConversionServiceParameterValueMapper;
4545
import org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker;
4646
import org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor;
47+
import org.springframework.cglib.proxy.Enhancer;
48+
import org.springframework.cglib.proxy.FixedValue;
4749
import org.springframework.context.ApplicationContext;
4850
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4951
import org.springframework.context.annotation.Bean;
@@ -236,6 +238,15 @@ public void getEndpointShouldFindParentExtension() {
236238
});
237239
}
238240

241+
@Test
242+
public void getEndpointsWhenHasProxiedEndpointShouldReturnEndpoint() {
243+
load(ProxiedSpecializedEndpointsConfiguration.class, (context) -> {
244+
SpecializedEndpointDiscoverer discoverer = new SpecializedEndpointDiscoverer(context);
245+
Map<EndpointId, SpecializedExposableEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
246+
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"), EndpointId.of("specialized"));
247+
});
248+
}
249+
239250
@Test
240251
public void getEndpointsShouldApplyFilters() {
241252
load(SpecializedEndpointsConfiguration.class, (context) -> {
@@ -327,6 +338,19 @@ static class EmptyConfiguration {
327338

328339
}
329340

341+
@Configuration
342+
static class ProxiedSpecializedTestEndpointConfiguration {
343+
344+
@Bean
345+
public SpecializedExtension specializedExtension() {
346+
Enhancer enhancer = new Enhancer();
347+
enhancer.setSuperclass(SpecializedExtension.class);
348+
enhancer.setCallback((FixedValue) () -> null);
349+
return (SpecializedExtension) enhancer.create();
350+
}
351+
352+
}
353+
330354
@Configuration
331355
static class TestEndpointConfiguration {
332356

@@ -387,6 +411,11 @@ static class SubSpecializedEndpointsConfiguration {
387411

388412
}
389413

414+
@Import({ TestEndpoint.class, SpecializedTestEndpoint.class, ProxiedSpecializedTestEndpointConfiguration.class })
415+
static class ProxiedSpecializedEndpointsConfiguration {
416+
417+
}
418+
390419
@Endpoint(id = "test")
391420
static class TestEndpoint {
392421

0 commit comments

Comments
 (0)