Skip to content

Commit b4d447f

Browse files
committed
isLiteConfigurationCandidate considers @componentscan and @ImportResource as indicators as well
Issue: SPR-11769
1 parent 89fc3c0 commit b4d447f

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassUtils.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,8 @@
1717
package org.springframework.context.annotation;
1818

1919
import java.io.IOException;
20+
import java.util.HashSet;
21+
import java.util.Set;
2022

2123
import org.apache.commons.logging.Log;
2224
import org.apache.commons.logging.LogFactory;
@@ -46,8 +48,18 @@ abstract class ConfigurationClassUtils {
4648
private static final String CONFIGURATION_CLASS_ATTRIBUTE =
4749
Conventions.getQualifiedAttributeName(ConfigurationClassPostProcessor.class, "configurationClass");
4850

51+
4952
private static final Log logger = LogFactory.getLog(ConfigurationClassUtils.class);
5053

54+
private static final Set<String> candidateIndicators = new HashSet<String>(4);
55+
56+
static {
57+
candidateIndicators.add(Component.class.getName());
58+
candidateIndicators.add(ComponentScan.class.getName());
59+
candidateIndicators.add(Import.class.getName());
60+
candidateIndicators.add(ImportResource.class.getName());
61+
}
62+
5163

5264
/**
5365
* Check whether the given bean definition is a candidate for a configuration class
@@ -119,16 +131,23 @@ public static boolean isFullConfigurationCandidate(AnnotationMetadata metadata)
119131

120132
/**
121133
* Check the given metadata for a lite configuration class candidate
122-
* (i.e. a class annotated with {@code @Component} or just having
134+
* (e.g. a class annotated with {@code @Component} or just having
123135
* {@code @Import} declarations or {@code @Bean methods}).
124136
* @param metadata the metadata of the annotated class
125137
* @return {@code true} if the given class is to be processed as a lite
126138
* configuration class, just registering it and scanning it for {@code @Bean} methods
127139
*/
128140
public static boolean isLiteConfigurationCandidate(AnnotationMetadata metadata) {
129141
// Do not consider an interface or an annotation...
130-
return (!metadata.isInterface() && (metadata.isAnnotated(Component.class.getName()) ||
131-
metadata.isAnnotated(Import.class.getName()) || metadata.hasAnnotatedMethods(Bean.class.getName())));
142+
if (metadata.isInterface()) {
143+
return false;
144+
}
145+
for (String indicator : candidateIndicators) {
146+
if (metadata.isAnnotated(indicator)) {
147+
return true;
148+
}
149+
}
150+
return metadata.hasAnnotatedMethods(Bean.class.getName());
132151
}
133152

134153
/**

spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAndImportAnnotationInteractionTests.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,23 @@ public void componentScanViaImportUsingScan() {
7272
}
7373

7474

75-
@Configuration
7675
@ComponentScan("org.springframework.context.annotation.componentscan.simple")
77-
static class Config1 {
76+
static final class Config1 {
7877
}
7978

8079

81-
@Configuration
8280
@Import(org.springframework.context.annotation.componentscan.simple.SimpleComponent.class)
83-
static class Config2 {
81+
static final class Config2 {
8482
}
8583

8684

87-
@Configuration
8885
@Import(ImportedConfig.class)
89-
static class Config3 {
86+
static final class Config3 {
9087
}
9188

9289

93-
@Configuration
9490
@ComponentScan("org.springframework.context.annotation.componentscan.simple")
95-
public static class ImportedConfig {
91+
public static final class ImportedConfig {
9692
}
9793

9894
}

0 commit comments

Comments
 (0)