Support @⁠Import on interfaces

See gh-34805
Closes gh-34820

Signed-off-by: Daeho Kwon <trewq231@naver.com>
This commit is contained in:
Daeho Kwon
2025-04-25 03:29:00 +09:00
committed by Sam Brannen
parent 686705140e
commit a4d5800a6c
2 changed files with 74 additions and 1 deletions

View File

@@ -98,6 +98,7 @@ import org.springframework.util.StringUtils;
* @author Phillip Webb
* @author Sam Brannen
* @author Stephane Nicoll
* @author Daeho Kwon
* @since 3.0
* @see ConfigurationClassBeanDefinitionReader
*/
@@ -549,6 +550,9 @@ class ConfigurationClassParser {
* <p>For example, it is common for a {@code @Configuration} class to declare direct
* {@code @Import}s in addition to meta-imports originating from an {@code @Enable}
* annotation.
* <p>As of Spring Framework 7.0, {@code @Import} annotations declared on interfaces implemented by
* the configuration class are also considered. This allows imports to be triggered
* indirectly via marker interfaces or shared base interfaces.
* @param sourceClass the class to search
* @param imports the imports collected so far
* @param visited used to track visited classes to prevent infinite recursion
@@ -558,6 +562,9 @@ class ConfigurationClassParser {
throws IOException {
if (visited.add(sourceClass)) {
for (SourceClass ifc : sourceClass.getInterfaces()) {
collectImports(ifc, imports, visited);
}
for (SourceClass annotation : sourceClass.getAnnotations()) {
String annName = annotation.getMetadata().getClassName();
if (!annName.equals(Import.class.getName())) {