28
28
import org .springframework .core .type .StandardAnnotationMetadata ;
29
29
import org .springframework .core .type .classreading .MetadataReader ;
30
30
import org .springframework .core .type .classreading .MetadataReaderFactory ;
31
+ import org .springframework .stereotype .Component ;
31
32
32
33
/**
33
34
* Utilities for processing @{@link Configuration} classes.
34
35
*
35
36
* @author Chris Beams
37
+ * @author Juergen Hoeller
36
38
* @since 3.1
37
39
*/
38
40
abstract class ConfigurationClassUtils {
@@ -48,8 +50,9 @@ abstract class ConfigurationClassUtils {
48
50
49
51
50
52
/**
51
- * Check whether the given bean definition is a candidate for a configuration class,
52
- * and mark it accordingly.
53
+ * Check whether the given bean definition is a candidate for a configuration class
54
+ * (or a nested component class declared within a configuration/component class,
55
+ * to be auto-registered as well), and mark it accordingly.
53
56
* @param beanDef the bean definition to check
54
57
* @param metadataReaderFactory the current factory in use by the caller
55
58
* @return whether the candidate qualifies as (any kind of) configuration class
@@ -92,22 +95,45 @@ else if (isLiteConfigurationCandidate(metadata)) {
92
95
return false ;
93
96
}
94
97
98
+ /**
99
+ * Check the given metadata for a configuration class candidate
100
+ * (or nested component class declared within a configuration/component class).
101
+ * @param metadata the metadata of the annotated class
102
+ * @return {@code true} if the given class is to be registered as a
103
+ * reflection-detected bean definition; {@code false} otherwise
104
+ */
95
105
public static boolean isConfigurationCandidate (AnnotationMetadata metadata ) {
96
106
return (isFullConfigurationCandidate (metadata ) || isLiteConfigurationCandidate (metadata ));
97
107
}
98
108
109
+ /**
110
+ * Check the given metadata for a full configuration class candidate
111
+ * (i.e. a class annotated with {@code @Configuration}).
112
+ * @param metadata the metadata of the annotated class
113
+ * @return {@code true} if the given class is to be processed as a full
114
+ * configuration class, including cross-method call interception
115
+ */
99
116
public static boolean isFullConfigurationCandidate (AnnotationMetadata metadata ) {
100
117
return metadata .isAnnotated (Configuration .class .getName ());
101
118
}
102
119
120
+ /**
121
+ * Check the given metadata for a lite configuration class candidate
122
+ * (i.e. a class annotated with {@code @Component} or just having
123
+ * {@code @Import} declarations or {@code @Bean methods}).
124
+ * @param metadata the metadata of the annotated class
125
+ * @return {@code true} if the given class is to be processed as a lite
126
+ * configuration class, just registering it and scanning it for {@code @Bean} methods
127
+ */
103
128
public static boolean isLiteConfigurationCandidate (AnnotationMetadata metadata ) {
104
129
// Do not consider an interface or an annotation...
105
- return (!metadata .isInterface () && (
130
+ return (!metadata .isInterface () && (metadata . isAnnotated ( Component . class . getName ()) ||
106
131
metadata .isAnnotated (Import .class .getName ()) || metadata .hasAnnotatedMethods (Bean .class .getName ())));
107
132
}
108
133
109
134
/**
110
- * Determine whether the given bean definition indicates a full @Configuration class.
135
+ * Determine whether the given bean definition indicates a full {@code @Configuration}
136
+ * class, through checking {@link #checkConfigurationClassCandidate}'s metadata marker.
111
137
*/
112
138
public static boolean isFullConfigurationClass (BeanDefinition beanDef ) {
113
139
return CONFIGURATION_CLASS_FULL .equals (beanDef .getAttribute (CONFIGURATION_CLASS_ATTRIBUTE ));
0 commit comments