diff --git a/spring-context/src/main/java/org/springframework/context/annotation/BeanAnnotationHelper.java b/spring-context/src/main/java/org/springframework/context/annotation/BeanAnnotationHelper.java index b28ab0492b6..c4afe223252 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/BeanAnnotationHelper.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/BeanAnnotationHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,13 +36,14 @@ class BeanAnnotationHelper { public static String determineBeanNameFor(Method beanMethod) { // By default, the bean name is the name of the @Bean-annotated method String beanName = beanMethod.getName(); - // Check to see if the user has explicitly set a custom bean name... Bean bean = AnnotatedElementUtils.findMergedAnnotation(beanMethod, Bean.class); - if (bean != null && bean.name().length > 0) { - beanName = bean.name()[0]; + if (bean != null) { + String[] names = bean.name(); + if (names.length > 0) { + beanName = names[0]; + } } - return beanName; } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java index c67cd0cd683..ce9bb633168 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java @@ -626,22 +626,20 @@ public class AnnotatedElementUtils { * attributes of the same name from higher levels, and * {@link AliasFor @AliasFor} semantics are fully supported, both * within a single annotation and within the annotation hierarchy. - *

In contrast to {@link #getAllAnnotationAttributes}, the search - * algorithm used by this method will stop searching the annotation - * hierarchy once the first annotation of the specified - * {@code annotationType} has been found. As a consequence, additional - * annotations of the specified {@code annotationType} will be ignored. + *

In contrast to {@link #getAllAnnotationAttributes}, the search algorithm + * used by this method will stop searching the annotation hierarchy once the + * first annotation of the specified {@code annotationType} has been found. + * As a consequence, additional annotations of the specified + * {@code annotationType} will be ignored. *

This method follows find semantics as described in the * {@linkplain AnnotatedElementUtils class-level javadoc}. * @param element the annotated element * @param annotationType the annotation type to find * @param classValuesAsString whether to convert Class references into * Strings or to preserve them as Class references - * @param nestedAnnotationsAsMap whether to convert nested Annotation - * instances into {@code AnnotationAttributes} maps or to preserve them - * as Annotation instances - * @return the merged {@code AnnotationAttributes}, or {@code null} if - * not found + * @param nestedAnnotationsAsMap whether to convert nested Annotation instances into + * {@code AnnotationAttributes} maps or to preserve them as Annotation instances + * @return the merged {@code AnnotationAttributes}, or {@code null} if not found * @since 4.2 * @see #findMergedAnnotation(AnnotatedElement, Class) * @see #getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean) diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java index 46c89574cfb..c782d566e7b 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java @@ -29,12 +29,11 @@ import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; /** - * ASM visitor which looks for the annotations defined on a class or method, including - * tracking meta-annotations. + * ASM visitor which looks for annotations defined on a class or method, + * including meta-annotations. * - *

As of Spring 3.1.1, this visitor is fully recursive, taking into account any nested - * annotations or nested annotation arrays. These annotations are in turn read into - * {@link AnnotationAttributes} map structures. + *

This visitor is fully recursive, taking into account any nested + * annotations or nested annotation arrays. * * @author Juergen Hoeller * @author Chris Beams @@ -77,9 +76,7 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib Annotation[] metaAnnotations = AnnotationUtils.getAnnotations(annotationClass); if (!ObjectUtils.isEmpty(metaAnnotations)) { for (Annotation metaAnnotation : metaAnnotations) { - if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) { - recursivelyCollectMetaAnnotations(visited, metaAnnotation); - } + recursivelyCollectMetaAnnotations(visited, metaAnnotation); } } if (this.metaAnnotationMap != null) { @@ -111,7 +108,7 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib } catch (Throwable ex) { if (logger.isDebugEnabled()) { - logger.debug("Failed to introspect meta-annotations on [" + annotation + "]: " + ex); + logger.debug("Failed to introspect meta-annotations on " + annotation + ": " + ex); } } }