|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2011 the original author or authors. |
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -16,8 +16,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.context.annotation; |
|
|
|
package org.springframework.context.annotation; |
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.context.annotation.MetadataUtils.attributesFor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
@ -29,6 +27,7 @@ import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; |
|
|
|
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; |
|
|
|
import org.springframework.beans.factory.annotation.Autowire; |
|
|
|
import org.springframework.beans.factory.annotation.Autowire; |
|
|
|
import org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor; |
|
|
|
import org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor; |
|
|
|
@ -46,6 +45,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
|
|
|
import org.springframework.beans.factory.support.GenericBeanDefinition; |
|
|
|
import org.springframework.beans.factory.support.GenericBeanDefinition; |
|
|
|
import org.springframework.beans.factory.support.RootBeanDefinition; |
|
|
|
import org.springframework.beans.factory.support.RootBeanDefinition; |
|
|
|
import org.springframework.core.annotation.AnnotationAttributes; |
|
|
|
import org.springframework.core.annotation.AnnotationAttributes; |
|
|
|
|
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.core.io.ResourceLoader; |
|
|
|
import org.springframework.core.io.ResourceLoader; |
|
|
|
import org.springframework.core.type.AnnotationMetadata; |
|
|
|
import org.springframework.core.type.AnnotationMetadata; |
|
|
|
@ -54,6 +54,8 @@ import org.springframework.core.type.classreading.MetadataReader; |
|
|
|
import org.springframework.core.type.classreading.MetadataReaderFactory; |
|
|
|
import org.springframework.core.type.classreading.MetadataReaderFactory; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.context.annotation.MetadataUtils.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Reads a given fully-populated set of ConfigurationClass instances, registering bean |
|
|
|
* Reads a given fully-populated set of ConfigurationClass instances, registering bean |
|
|
|
* definitions with the given {@link BeanDefinitionRegistry} based on its contents. |
|
|
|
* definitions with the given {@link BeanDefinitionRegistry} based on its contents. |
|
|
|
@ -79,7 +81,10 @@ class ConfigurationClassBeanDefinitionReader { |
|
|
|
|
|
|
|
|
|
|
|
private final MetadataReaderFactory metadataReaderFactory; |
|
|
|
private final MetadataReaderFactory metadataReaderFactory; |
|
|
|
|
|
|
|
|
|
|
|
private ResourceLoader resourceLoader; |
|
|
|
private final ResourceLoader resourceLoader; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Environment environment; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new {@link ConfigurationClassBeanDefinitionReader} instance that will be used |
|
|
|
* Create a new {@link ConfigurationClassBeanDefinitionReader} instance that will be used |
|
|
|
@ -89,13 +94,14 @@ class ConfigurationClassBeanDefinitionReader { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ConfigurationClassBeanDefinitionReader(BeanDefinitionRegistry registry, SourceExtractor sourceExtractor, |
|
|
|
public ConfigurationClassBeanDefinitionReader(BeanDefinitionRegistry registry, SourceExtractor sourceExtractor, |
|
|
|
ProblemReporter problemReporter, MetadataReaderFactory metadataReaderFactory, |
|
|
|
ProblemReporter problemReporter, MetadataReaderFactory metadataReaderFactory, |
|
|
|
ResourceLoader resourceLoader) { |
|
|
|
ResourceLoader resourceLoader, Environment environment) { |
|
|
|
|
|
|
|
|
|
|
|
this.registry = registry; |
|
|
|
this.registry = registry; |
|
|
|
this.sourceExtractor = sourceExtractor; |
|
|
|
this.sourceExtractor = sourceExtractor; |
|
|
|
this.problemReporter = problemReporter; |
|
|
|
this.problemReporter = problemReporter; |
|
|
|
this.metadataReaderFactory = metadataReaderFactory; |
|
|
|
this.metadataReaderFactory = metadataReaderFactory; |
|
|
|
this.resourceLoader = resourceLoader; |
|
|
|
this.resourceLoader = resourceLoader; |
|
|
|
|
|
|
|
this.environment = environment; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -294,12 +300,12 @@ class ConfigurationClassBeanDefinitionReader { |
|
|
|
// Instantiate the specified BeanDefinitionReader
|
|
|
|
// Instantiate the specified BeanDefinitionReader
|
|
|
|
BeanDefinitionReader readerInstance = |
|
|
|
BeanDefinitionReader readerInstance = |
|
|
|
readerClass.getConstructor(BeanDefinitionRegistry.class).newInstance(this.registry); |
|
|
|
readerClass.getConstructor(BeanDefinitionRegistry.class).newInstance(this.registry); |
|
|
|
|
|
|
|
|
|
|
|
// Delegate the current ResourceLoader to it if possible
|
|
|
|
// Delegate the current ResourceLoader to it if possible
|
|
|
|
if (readerInstance instanceof AbstractBeanDefinitionReader) { |
|
|
|
if (readerInstance instanceof AbstractBeanDefinitionReader) { |
|
|
|
((AbstractBeanDefinitionReader)readerInstance).setResourceLoader(this.resourceLoader); |
|
|
|
AbstractBeanDefinitionReader abdr = ((AbstractBeanDefinitionReader) readerInstance); |
|
|
|
|
|
|
|
abdr.setResourceLoader(this.resourceLoader); |
|
|
|
|
|
|
|
abdr.setEnvironment(this.environment); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readerInstanceCache.put(readerClass, readerInstance); |
|
|
|
readerInstanceCache.put(readerClass, readerInstance); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Exception ex) { |
|
|
|
@ -354,6 +360,7 @@ class ConfigurationClassBeanDefinitionReader { |
|
|
|
* declare at least one {@link Bean @Bean} method. |
|
|
|
* declare at least one {@link Bean @Bean} method. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static class InvalidConfigurationImportProblem extends Problem { |
|
|
|
private static class InvalidConfigurationImportProblem extends Problem { |
|
|
|
|
|
|
|
|
|
|
|
public InvalidConfigurationImportProblem(String className, Resource resource, AnnotationMetadata metadata) { |
|
|
|
public InvalidConfigurationImportProblem(String className, Resource resource, AnnotationMetadata metadata) { |
|
|
|
super(String.format("%s was @Import'ed but is not annotated with @Configuration " + |
|
|
|
super(String.format("%s was @Import'ed but is not annotated with @Configuration " + |
|
|
|
"nor does it declare any @Bean methods; it does not implement ImportSelector " + |
|
|
|
"nor does it declare any @Bean methods; it does not implement ImportSelector " + |
|
|
|
|