Commit 12a16dcf authored by Phillip Webb's avatar Phillip Webb

Merge branch '2.0.x'

parents 578f093d 5183dd12
...@@ -30,6 +30,7 @@ import java.util.function.Function; ...@@ -30,6 +30,7 @@ import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.boot.actuate.endpoint.EndpointFilter; import org.springframework.boot.actuate.endpoint.EndpointFilter;
...@@ -131,12 +132,15 @@ public abstract class EndpointDiscoverer<E extends ExposableEndpoint<O>, O exten ...@@ -131,12 +132,15 @@ public abstract class EndpointDiscoverer<E extends ExposableEndpoint<O>, O exten
String[] beanNames = BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors( String[] beanNames = BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors(
this.applicationContext, Endpoint.class); this.applicationContext, Endpoint.class);
for (String beanName : beanNames) { for (String beanName : beanNames) {
EndpointBean endpointBean = createEndpointBean(beanName); if (!ScopedProxyUtils.isScopedTarget(beanName)) {
EndpointBean previous = byId.putIfAbsent(endpointBean.getId(), endpointBean); EndpointBean endpointBean = createEndpointBean(beanName);
Assert.state(previous == null, EndpointBean previous = byId.putIfAbsent(endpointBean.getId(),
() -> "Found two endpoints with the id '" + endpointBean.getId() endpointBean);
+ "': '" + endpointBean.getBeanName() + "' and '" Assert.state(previous == null,
+ previous.getBeanName() + "'"); () -> "Found two endpoints with the id '" + endpointBean.getId()
+ "': '" + endpointBean.getBeanName() + "' and '"
+ previous.getBeanName() + "'");
}
} }
return byId.values(); return byId.values();
} }
......
...@@ -148,6 +148,18 @@ public class EndpointDiscovererTests { ...@@ -148,6 +148,18 @@ public class EndpointDiscovererTests {
"Found two endpoints with the id 'test': ")); "Found two endpoints with the id 'test': "));
} }
@Test
public void getEndpointsWhenEndpointsArePrefixedWithScopedTargetShouldRegisterOnlyOneEndpoint() {
load(ScopedTargetEndpointConfiguration.class, (context) -> {
TestEndpoint expectedEndpoint = context
.getBean(ScopedTargetEndpointConfiguration.class).testEndpoint();
Collection<TestExposableEndpoint> endpoints = new TestEndpointDiscoverer(
context).getEndpoints();
assertThat(endpoints).flatExtracting(TestExposableEndpoint::getEndpointBean)
.containsOnly(expectedEndpoint);
});
}
@Test @Test
public void getEndpointsWhenTtlSetToZeroShouldNotCacheInvokeCalls() { public void getEndpointsWhenTtlSetToZeroShouldNotCacheInvokeCalls() {
load(TestEndpointConfiguration.class, (context) -> { load(TestEndpointConfiguration.class, (context) -> {
...@@ -393,6 +405,21 @@ public class EndpointDiscovererTests { ...@@ -393,6 +405,21 @@ public class EndpointDiscovererTests {
} }
@Configuration
static class ScopedTargetEndpointConfiguration {
@Bean
public TestEndpoint testEndpoint() {
return new TestEndpoint();
}
@Bean(name = "scopedTarget.testEndpoint")
public TestEndpoint scopedTargetTestEndpoint() {
return new TestEndpoint();
}
}
@Import({ TestEndpoint.class, SpecializedTestEndpoint.class, @Import({ TestEndpoint.class, SpecializedTestEndpoint.class,
SpecializedExtension.class }) SpecializedExtension.class })
static class SpecializedEndpointsConfiguration { static class SpecializedEndpointsConfiguration {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment