From 5111b03aa3e7510c8d321070702a0fa0d0a515c0 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 5 Sep 2017 09:51:33 +0200 Subject: [PATCH] Remove duplicated method This commit removes the beanNamesForAnnotationIncludingAncestors method as it is now part of Spring Framework's BeanFactoryUtils. Closes gh-10150 --- .../AnnotationEndpointDiscoverer.java | 31 ++----------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/endpoint/AnnotationEndpointDiscoverer.java b/spring-boot/src/main/java/org/springframework/boot/endpoint/AnnotationEndpointDiscoverer.java index 8d68ee1e74..3f6af441ad 100644 --- a/spring-boot/src/main/java/org/springframework/boot/endpoint/AnnotationEndpointDiscoverer.java +++ b/spring-boot/src/main/java/org/springframework/boot/endpoint/AnnotationEndpointDiscoverer.java @@ -19,7 +19,6 @@ package org.springframework.boot.endpoint; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -29,8 +28,7 @@ import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; -import org.springframework.beans.factory.HierarchicalBeanFactory; -import org.springframework.beans.factory.ListableBeanFactory; +import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.context.ApplicationContext; import org.springframework.core.MethodIntrospector; import org.springframework.core.annotation.AnnotatedElementUtils; @@ -38,7 +36,6 @@ import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.ObjectUtils; -import org.springframework.util.StringUtils; /** * A base {@link EndpointDiscoverer} implementation that discovers {@link Endpoint} beans @@ -92,7 +89,7 @@ public abstract class AnnotationEndpointDiscoverer } private Map, EndpointInfo> discoverEndpoints(EndpointExposure exposure) { - String[] beanNames = beanNamesForAnnotationIncludingAncestors( + String[] beanNames = BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors( this.applicationContext, Endpoint.class); Map, EndpointInfo> endpoints = new LinkedHashMap<>(); Map> endpointsById = new LinkedHashMap<>(); @@ -125,7 +122,7 @@ public abstract class AnnotationEndpointDiscoverer if (extensionType == null) { return Collections.emptyMap(); } - String[] beanNames = beanNamesForAnnotationIncludingAncestors( + String[] beanNames = BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors( this.applicationContext, extensionType); Map, EndpointExtensionInfo> extensions = new HashMap<>(); for (String beanName : beanNames) { @@ -154,28 +151,6 @@ public abstract class AnnotationEndpointDiscoverer } - private static String[] beanNamesForAnnotationIncludingAncestors( - ListableBeanFactory lbf, Class annotationType) { - Assert.notNull(lbf, "ListableBeanFactory must not be null"); - String[] result = lbf.getBeanNamesForAnnotation(annotationType); - if (lbf instanceof HierarchicalBeanFactory) { - HierarchicalBeanFactory hbf = (HierarchicalBeanFactory) lbf; - if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) { - String[] parentResult = beanNamesForAnnotationIncludingAncestors( - (ListableBeanFactory) hbf.getParentBeanFactory(), annotationType); - List resultList = new ArrayList<>(); - resultList.addAll(Arrays.asList(result)); - for (String beanName : parentResult) { - if (!resultList.contains(beanName) && !hbf.containsLocalBean(beanName)) { - resultList.add(beanName); - } - } - result = StringUtils.toStringArray(resultList); - } - } - return result; - } - private EndpointInfo getEndpointInfo(Map, EndpointInfo> endpoints, Class beanType, Class endpointClass) { EndpointInfo endpoint = endpoints.get(endpointClass);