27
27
28
28
import org .apache .commons .logging .Log ;
29
29
import org .apache .commons .logging .LogFactory ;
30
- import org .springframework .beans .BeanUtils ;
31
30
import org .springframework .beans .factory .annotation .AnnotatedBeanDefinition ;
32
31
import org .springframework .beans .factory .annotation .Autowire ;
33
32
import org .springframework .beans .factory .annotation .RequiredAnnotationBeanPostProcessor ;
44
43
import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
45
44
import org .springframework .beans .factory .support .GenericBeanDefinition ;
46
45
import org .springframework .beans .factory .support .RootBeanDefinition ;
47
- import org .springframework .context .EnvironmentAware ;
48
- import org .springframework .context .ResourceLoaderAware ;
49
- import org .springframework .core .Conventions ;
50
- import org .springframework .core .env .Environment ;
51
46
import org .springframework .core .io .Resource ;
52
47
import org .springframework .core .io .ResourceLoader ;
53
48
import org .springframework .core .type .AnnotationMetadata ;
54
49
import org .springframework .core .type .MethodMetadata ;
55
- import org .springframework .core .type .StandardAnnotationMetadata ;
56
50
import org .springframework .core .type .classreading .MetadataReader ;
57
51
import org .springframework .core .type .classreading .MetadataReaderFactory ;
58
- import org .springframework .core .type .classreading .SimpleMetadataReaderFactory ;
59
- import org .springframework .stereotype .Component ;
60
52
import org .springframework .util .StringUtils ;
61
53
62
54
/**
74
66
*/
75
67
public class ConfigurationClassBeanDefinitionReader {
76
68
77
- private static final String CONFIGURATION_CLASS_FULL = "full" ;
78
-
79
- private static final String CONFIGURATION_CLASS_LITE = "lite" ;
80
-
81
- private static final String CONFIGURATION_CLASS_ATTRIBUTE =
82
- Conventions .getQualifiedAttributeName (ConfigurationClassPostProcessor .class , "configurationClass" );
83
-
84
69
private static final Log logger = LogFactory .getLog (ConfigurationClassBeanDefinitionReader .class );
85
-
70
+
86
71
private final BeanDefinitionRegistry registry ;
87
72
88
73
private final SourceExtractor sourceExtractor ;
@@ -93,28 +78,21 @@ public class ConfigurationClassBeanDefinitionReader {
93
78
94
79
private ResourceLoader resourceLoader ;
95
80
96
- private Environment environment ;
97
-
98
- private final ComponentScanAnnotationParser componentScanParser ;
99
-
100
81
/**
101
82
* Create a new {@link ConfigurationClassBeanDefinitionReader} instance that will be used
102
83
* to populate the given {@link BeanDefinitionRegistry}.
103
84
* @param problemReporter
104
85
* @param metadataReaderFactory
105
86
*/
106
- public ConfigurationClassBeanDefinitionReader (final BeanDefinitionRegistry registry , SourceExtractor sourceExtractor ,
87
+ public ConfigurationClassBeanDefinitionReader (BeanDefinitionRegistry registry , SourceExtractor sourceExtractor ,
107
88
ProblemReporter problemReporter , MetadataReaderFactory metadataReaderFactory ,
108
- ResourceLoader resourceLoader , Environment environment ) {
89
+ ResourceLoader resourceLoader ) {
109
90
110
91
this .registry = registry ;
111
92
this .sourceExtractor = sourceExtractor ;
112
93
this .problemReporter = problemReporter ;
113
94
this .metadataReaderFactory = metadataReaderFactory ;
114
95
this .resourceLoader = resourceLoader ;
115
- this .environment = environment ;
116
-
117
- this .componentScanParser = new ComponentScanAnnotationParser (resourceLoader , environment , registry );
118
96
}
119
97
120
98
@@ -133,8 +111,6 @@ public void loadBeanDefinitions(Set<ConfigurationClass> configurationModel) {
133
111
* class itself, all its {@link Bean} methods
134
112
*/
135
113
private void loadBeanDefinitionsForConfigurationClass (ConfigurationClass configClass ) {
136
- AnnotationMetadata metadata = configClass .getMetadata ();
137
- componentScanParser .parse (metadata );
138
114
doLoadBeanDefinitionForConfigurationClassIfNecessary (configClass );
139
115
for (BeanMethod beanMethod : configClass .getBeanMethods ()) {
140
116
loadBeanDefinitionsForBeanMethod (beanMethod );
@@ -155,7 +131,7 @@ private void doLoadBeanDefinitionForConfigurationClassIfNecessary(ConfigurationC
155
131
BeanDefinition configBeanDef = new GenericBeanDefinition ();
156
132
String className = configClass .getMetadata ().getClassName ();
157
133
configBeanDef .setBeanClassName (className );
158
- if (checkConfigurationClassCandidate (configBeanDef , this .metadataReaderFactory )) {
134
+ if (ConfigurationClassUtils . checkConfigurationClassCandidate (configBeanDef , this .metadataReaderFactory )) {
159
135
String configBeanName = BeanDefinitionReaderUtils .registerWithGeneratedName ((AbstractBeanDefinition )configBeanDef , this .registry );
160
136
configClass .setBeanName (configBeanName );
161
137
if (logger .isDebugEnabled ()) {
@@ -311,59 +287,6 @@ private void loadBeanDefinitionsFromImportedResources(Map<String, Class<?>> impo
311
287
}
312
288
313
289
314
- /**
315
- * Check whether the given bean definition is a candidate for a configuration class,
316
- * and mark it accordingly.
317
- * @param beanDef the bean definition to check
318
- * @param metadataReaderFactory the current factory in use by the caller
319
- * @return whether the candidate qualifies as (any kind of) configuration class
320
- */
321
- public static boolean checkConfigurationClassCandidate (BeanDefinition beanDef , MetadataReaderFactory metadataReaderFactory ) {
322
- AnnotationMetadata metadata = null ;
323
-
324
- // Check already loaded Class if present...
325
- // since we possibly can't even load the class file for this Class.
326
- if (beanDef instanceof AbstractBeanDefinition && ((AbstractBeanDefinition ) beanDef ).hasBeanClass ()) {
327
- metadata = new StandardAnnotationMetadata (((AbstractBeanDefinition ) beanDef ).getBeanClass ());
328
- }
329
- else {
330
- String className = beanDef .getBeanClassName ();
331
- if (className != null ) {
332
- try {
333
- MetadataReader metadataReader = metadataReaderFactory .getMetadataReader (className );
334
- metadata = metadataReader .getAnnotationMetadata ();
335
- }
336
- catch (IOException ex ) {
337
- if (logger .isDebugEnabled ()) {
338
- logger .debug ("Could not find class file for introspecting factory methods: " + className , ex );
339
- }
340
- return false ;
341
- }
342
- }
343
- }
344
-
345
- if (metadata != null ) {
346
- if (metadata .isAnnotated (Configuration .class .getName ())) {
347
- beanDef .setAttribute (CONFIGURATION_CLASS_ATTRIBUTE , CONFIGURATION_CLASS_FULL );
348
- return true ;
349
- }
350
- else if (metadata .isAnnotated (Component .class .getName ()) ||
351
- metadata .hasAnnotatedMethods (Bean .class .getName ())) {
352
- beanDef .setAttribute (CONFIGURATION_CLASS_ATTRIBUTE , CONFIGURATION_CLASS_LITE );
353
- return true ;
354
- }
355
- }
356
- return false ;
357
- }
358
-
359
- /**
360
- * Determine whether the given bean definition indicates a full @Configuration class.
361
- */
362
- public static boolean isFullConfigurationClass (BeanDefinition beanDef ) {
363
- return CONFIGURATION_CLASS_FULL .equals (beanDef .getAttribute (CONFIGURATION_CLASS_ATTRIBUTE ));
364
- }
365
-
366
-
367
290
/**
368
291
* {@link RootBeanDefinition} marker subclass used to signify that a bean definition
369
292
* was created from a configuration class as opposed to any other configuration source.
0 commit comments