@@ -78,7 +78,9 @@ abstract class ConfigurationClassUtils {
78
78
* @param metadataReaderFactory the current factory in use by the caller
79
79
* @return whether the candidate qualifies as (any kind of) configuration class
80
80
*/
81
- public static boolean checkConfigurationClassCandidate (BeanDefinition beanDef , MetadataReaderFactory metadataReaderFactory ) {
81
+ public static boolean checkConfigurationClassCandidate (
82
+ BeanDefinition beanDef , MetadataReaderFactory metadataReaderFactory ) {
83
+
82
84
String className = beanDef .getBeanClassName ();
83
85
if (className == null || beanDef .getFactoryMethodName () != null ) {
84
86
return false ;
@@ -103,7 +105,8 @@ else if (beanDef instanceof AbstractBeanDefinition && ((AbstractBeanDefinition)
103
105
}
104
106
catch (IOException ex ) {
105
107
if (logger .isDebugEnabled ()) {
106
- logger .debug ("Could not find class file for introspecting configuration annotations: " + className , ex );
108
+ logger .debug ("Could not find class file for introspecting configuration annotations: " +
109
+ className , ex );
107
110
}
108
111
return false ;
109
112
}
@@ -116,7 +119,7 @@ else if (isLiteConfigurationCandidate(metadata)) {
116
119
beanDef .setAttribute (CONFIGURATION_CLASS_ATTRIBUTE , CONFIGURATION_CLASS_LITE );
117
120
}
118
121
else {
119
- return false ;
122
+ return hasNestedConfigurationClass ( metadata , metadataReaderFactory ) ;
120
123
}
121
124
122
125
// It's a full or lite configuration candidate... Let's determine the order value, if any.
@@ -128,6 +131,40 @@ else if (isLiteConfigurationCandidate(metadata)) {
128
131
return true ;
129
132
}
130
133
134
+ /**
135
+ * Check whether the specified class declares a nested configuration class.
136
+ */
137
+ private static boolean hasNestedConfigurationClass (
138
+ AnnotationMetadata metadata , MetadataReaderFactory metadataReaderFactory ) {
139
+
140
+ // Potentially nested configuration classes...
141
+ if (metadata instanceof StandardAnnotationMetadata ) {
142
+ Class <?> beanClass = ((StandardAnnotationMetadata ) metadata ).getIntrospectedClass ();
143
+ for (Class <?> memberClass : beanClass .getDeclaredClasses ()) {
144
+ if (isConfigurationCandidate (new StandardAnnotationMetadata (memberClass ))) {
145
+ return true ;
146
+ }
147
+ }
148
+ }
149
+ else {
150
+ for (String memberName : metadata .getMemberClassNames ()) {
151
+ try {
152
+ MetadataReader metadataReader = metadataReaderFactory .getMetadataReader (memberName );
153
+ if (isConfigurationCandidate (metadataReader .getAnnotationMetadata ())) {
154
+ return true ;
155
+ }
156
+ }
157
+ catch (IOException ex ) {
158
+ if (logger .isDebugEnabled ()) {
159
+ logger .debug ("Could not find class file for introspecting configuration annotations: " +
160
+ memberName , ex );
161
+ }
162
+ }
163
+ }
164
+ }
165
+ return false ;
166
+ }
167
+
131
168
/**
132
169
* Check the given metadata for a configuration class candidate
133
170
* (or nested component class declared within a configuration/component class).
0 commit comments