diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index 2b6cbfe523..3b7be52f8b 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -531,7 +531,7 @@ class ConfigurationClassParser { if (visited.add(sourceClass)) { for (SourceClass annotation : sourceClass.getAnnotations()) { String annName = annotation.getMetadata().getClassName(); - if (!annName.startsWith("java") && !annName.equals(Import.class.getName())) { + if (!annName.equals(Import.class.getName())) { collectImports(annotation, imports, visited); } } @@ -539,8 +539,6 @@ class ConfigurationClassParser { } } - - private void processImports(ConfigurationClass configClass, SourceClass currentSourceClass, Collection importCandidates, boolean checkForCircularImports) { @@ -562,8 +560,7 @@ class ConfigurationClassParser { ParserStrategyUtils.invokeAwareMethods( selector, this.environment, this.resourceLoader, this.registry); if (selector instanceof DeferredImportSelector) { - this.deferredImportSelectorHandler.handle( - configClass, (DeferredImportSelector) selector); + this.deferredImportSelectorHandler.handle(configClass, (DeferredImportSelector) selector); } else { String[] importClassNames = selector.selectImports(currentSourceClass.getMetadata()); @@ -1016,13 +1013,32 @@ class ConfigurationClassParser { public Set getAnnotations() { Set result = new LinkedHashSet<>(); - for (String className : this.metadata.getAnnotationTypes()) { - try { - result.add(getRelated(className)); + if (this.source instanceof Class) { + Class sourceClass = (Class) this.source; + for (Annotation ann : sourceClass.getAnnotations()) { + Class annType = ann.annotationType(); + if (!annType.getName().startsWith("java")) { + try { + result.add(asSourceClass(annType)); + } + catch (Throwable ex) { + // An annotation not present on the classpath is being ignored + // by the JVM's class loading -> ignore here as well. + } + } } - catch (Throwable ex) { - // An annotation not present on the classpath is being ignored - // by the JVM's class loading -> ignore here as well. + } + else { + for (String className : this.metadata.getAnnotationTypes()) { + if (!className.startsWith("java")) { + try { + result.add(getRelated(className)); + } + catch (Throwable ex) { + // An annotation not present on the classpath is being ignored + // by the JVM's class loading -> ignore here as well. + } + } } } return result;