|
81 | 81 | * @author Chris Beams
|
82 | 82 | * @author Juergen Hoeller
|
83 | 83 | * @author Phillip Webb
|
| 84 | + * @author Sam Brannen |
84 | 85 | * @since 3.0
|
85 | 86 | */
|
86 | 87 | public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPostProcessor,
|
@@ -376,21 +377,30 @@ public void enhanceConfigurationClasses(ConfigurableListableBeanFactory beanFact
|
376 | 377 | for (String beanName : beanFactory.getBeanDefinitionNames()) {
|
377 | 378 | BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
|
378 | 379 | Object configClassAttr = beanDef.getAttribute(ConfigurationClassUtils.CONFIGURATION_CLASS_ATTRIBUTE);
|
| 380 | + AnnotationMetadata annotationMetadata = null; |
379 | 381 | MethodMetadata methodMetadata = null;
|
380 | 382 | if (beanDef instanceof AnnotatedBeanDefinition) {
|
381 |
| - methodMetadata = ((AnnotatedBeanDefinition) beanDef).getFactoryMethodMetadata(); |
| 383 | + AnnotatedBeanDefinition annotatedBeanDefinition = (AnnotatedBeanDefinition) beanDef; |
| 384 | + annotationMetadata = annotatedBeanDefinition.getMetadata(); |
| 385 | + methodMetadata = annotatedBeanDefinition.getFactoryMethodMetadata(); |
382 | 386 | }
|
383 | 387 | if ((configClassAttr != null || methodMetadata != null) && beanDef instanceof AbstractBeanDefinition) {
|
384 | 388 | // Configuration class (full or lite) or a configuration-derived @Bean method
|
385 |
| - // -> resolve bean class at this point... |
| 389 | + // -> eagerly resolve bean class at this point, unless it's a 'lite' configuration |
| 390 | + // or component class without @Bean methods. |
386 | 391 | AbstractBeanDefinition abd = (AbstractBeanDefinition) beanDef;
|
387 | 392 | if (!abd.hasBeanClass()) {
|
388 |
| - try { |
389 |
| - abd.resolveBeanClass(this.beanClassLoader); |
390 |
| - } |
391 |
| - catch (Throwable ex) { |
392 |
| - throw new IllegalStateException( |
393 |
| - "Cannot load configuration class: " + beanDef.getBeanClassName(), ex); |
| 393 | + boolean liteConfigurationCandidateWithoutBeanMethods = |
| 394 | + (ConfigurationClassUtils.CONFIGURATION_CLASS_LITE.equals(configClassAttr) && |
| 395 | + annotationMetadata != null && !ConfigurationClassUtils.hasBeanMethods(annotationMetadata)); |
| 396 | + if (!liteConfigurationCandidateWithoutBeanMethods) { |
| 397 | + try { |
| 398 | + abd.resolveBeanClass(this.beanClassLoader); |
| 399 | + } |
| 400 | + catch (Throwable ex) { |
| 401 | + throw new IllegalStateException( |
| 402 | + "Cannot load configuration class: " + beanDef.getBeanClassName(), ex); |
| 403 | + } |
394 | 404 | }
|
395 | 405 | }
|
396 | 406 | }
|
|
0 commit comments