2828import org .springframework .core .type .StandardAnnotationMetadata ;
2929import org .springframework .core .type .classreading .MetadataReader ;
3030import org .springframework .core .type .classreading .MetadataReaderFactory ;
31+ import org .springframework .stereotype .Component ;
3132
3233/**
3334 * Utilities for processing @{@link Configuration} classes.
3435 *
3536 * @author Chris Beams
37+ * @author Juergen Hoeller
3638 * @since 3.1
3739 */
3840abstract class ConfigurationClassUtils {
@@ -48,8 +50,9 @@ abstract class ConfigurationClassUtils {
4850
4951
5052 /**
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.
5356 * @param beanDef the bean definition to check
5457 * @param metadataReaderFactory the current factory in use by the caller
5558 * @return whether the candidate qualifies as (any kind of) configuration class
@@ -92,22 +95,45 @@ else if (isLiteConfigurationCandidate(metadata)) {
9295 return false ;
9396 }
9497
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+ */
95105 public static boolean isConfigurationCandidate (AnnotationMetadata metadata ) {
96106 return (isFullConfigurationCandidate (metadata ) || isLiteConfigurationCandidate (metadata ));
97107 }
98108
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+ */
99116 public static boolean isFullConfigurationCandidate (AnnotationMetadata metadata ) {
100117 return metadata .isAnnotated (Configuration .class .getName ());
101118 }
102119
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+ */
103128 public static boolean isLiteConfigurationCandidate (AnnotationMetadata metadata ) {
104129 // Do not consider an interface or an annotation...
105- return (!metadata .isInterface () && (
130+ return (!metadata .isInterface () && (metadata . isAnnotated ( Component . class . getName ()) ||
106131 metadata .isAnnotated (Import .class .getName ()) || metadata .hasAnnotatedMethods (Bean .class .getName ())));
107132 }
108133
109134 /**
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.
111137 */
112138 public static boolean isFullConfigurationClass (BeanDefinition beanDef ) {
113139 return CONFIGURATION_CLASS_FULL .equals (beanDef .getAttribute (CONFIGURATION_CLASS_ATTRIBUTE ));
0 commit comments