Skip to content

Commit 12a16dc

Browse files
committed
Merge branch '2.0.x'
2 parents 578f093 + 5183dd1 commit 12a16dc

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.function.Supplier;
3131
import java.util.stream.Collectors;
3232

33+
import org.springframework.aop.scope.ScopedProxyUtils;
3334
import org.springframework.beans.BeanUtils;
3435
import org.springframework.beans.factory.BeanFactoryUtils;
3536
import org.springframework.boot.actuate.endpoint.EndpointFilter;
@@ -131,12 +132,15 @@ private Collection<EndpointBean> createEndpointBeans() {
131132
String[] beanNames = BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors(
132133
this.applicationContext, Endpoint.class);
133134
for (String beanName : beanNames) {
134-
EndpointBean endpointBean = createEndpointBean(beanName);
135-
EndpointBean previous = byId.putIfAbsent(endpointBean.getId(), endpointBean);
136-
Assert.state(previous == null,
137-
() -> "Found two endpoints with the id '" + endpointBean.getId()
138-
+ "': '" + endpointBean.getBeanName() + "' and '"
139-
+ previous.getBeanName() + "'");
135+
if (!ScopedProxyUtils.isScopedTarget(beanName)) {
136+
EndpointBean endpointBean = createEndpointBean(beanName);
137+
EndpointBean previous = byId.putIfAbsent(endpointBean.getId(),
138+
endpointBean);
139+
Assert.state(previous == null,
140+
() -> "Found two endpoints with the id '" + endpointBean.getId()
141+
+ "': '" + endpointBean.getBeanName() + "' and '"
142+
+ previous.getBeanName() + "'");
143+
}
140144
}
141145
return byId.values();
142146
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ public void getEndpointsWhenTwoEndpointsHaveTheSameIdShouldThrowException() {
148148
"Found two endpoints with the id 'test': "));
149149
}
150150

151+
@Test
152+
public void getEndpointsWhenEndpointsArePrefixedWithScopedTargetShouldRegisterOnlyOneEndpoint() {
153+
load(ScopedTargetEndpointConfiguration.class, (context) -> {
154+
TestEndpoint expectedEndpoint = context
155+
.getBean(ScopedTargetEndpointConfiguration.class).testEndpoint();
156+
Collection<TestExposableEndpoint> endpoints = new TestEndpointDiscoverer(
157+
context).getEndpoints();
158+
assertThat(endpoints).flatExtracting(TestExposableEndpoint::getEndpointBean)
159+
.containsOnly(expectedEndpoint);
160+
});
161+
}
162+
151163
@Test
152164
public void getEndpointsWhenTtlSetToZeroShouldNotCacheInvokeCalls() {
153165
load(TestEndpointConfiguration.class, (context) -> {
@@ -393,6 +405,21 @@ public TestEndpoint testEndpointOne() {
393405

394406
}
395407

408+
@Configuration
409+
static class ScopedTargetEndpointConfiguration {
410+
411+
@Bean
412+
public TestEndpoint testEndpoint() {
413+
return new TestEndpoint();
414+
}
415+
416+
@Bean(name = "scopedTarget.testEndpoint")
417+
public TestEndpoint scopedTargetTestEndpoint() {
418+
return new TestEndpoint();
419+
}
420+
421+
}
422+
396423
@Import({ TestEndpoint.class, SpecializedTestEndpoint.class,
397424
SpecializedExtension.class })
398425
static class SpecializedEndpointsConfiguration {

0 commit comments

Comments
 (0)