[SPR-8393] AnnotatedBeanDefinitionReader's constructor now inherits the Environment of supplied BeanDefinitionRegistry.
This commit is contained in:
parent
18f5d90235
commit
74b169e886
|
|
@ -24,9 +24,11 @@ import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||||
import org.springframework.core.env.StandardEnvironment;
|
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.core.env.EnvironmentCapable;
|
||||||
|
import org.springframework.core.env.StandardEnvironment;
|
||||||
import org.springframework.core.type.AnnotationMetadata;
|
import org.springframework.core.type.AnnotationMetadata;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenient adapter for programmatic registration of annotated bean classes.
|
* Convenient adapter for programmatic registration of annotated bean classes.
|
||||||
|
|
@ -35,6 +37,7 @@ import org.springframework.core.type.AnnotationMetadata;
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
* @see AnnotationConfigApplicationContext#register
|
* @see AnnotationConfigApplicationContext#register
|
||||||
*/
|
*/
|
||||||
|
|
@ -48,17 +51,22 @@ public class AnnotatedBeanDefinitionReader {
|
||||||
|
|
||||||
private ScopeMetadataResolver scopeMetadataResolver = new AnnotationScopeMetadataResolver();
|
private ScopeMetadataResolver scopeMetadataResolver = new AnnotationScopeMetadataResolver();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@code AnnotatedBeanDefinitionReader} for the given bean factory.
|
* Create a new {@code AnnotatedBeanDefinitionReader} for the given bean factory.
|
||||||
* @param registry the {@code BeanFactory} to load bean definitions into,
|
* @param registry the {@code BeanFactory} to load bean definitions into,
|
||||||
* in the form of a {@code BeanDefinitionRegistry}
|
* in the form of a {@code BeanDefinitionRegistry}
|
||||||
*/
|
*/
|
||||||
public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry) {
|
public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry) {
|
||||||
|
Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
|
|
||||||
|
// Inherit Environment if possible
|
||||||
|
if (this.registry instanceof EnvironmentCapable) {
|
||||||
|
this.environment = ((EnvironmentCapable) this.registry).getEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the BeanDefinitionRegistry that this scanner operates on.
|
* Return the BeanDefinitionRegistry that this scanner operates on.
|
||||||
|
|
@ -82,8 +90,7 @@ public class AnnotatedBeanDefinitionReader {
|
||||||
* <p>The default is a {@link AnnotationBeanNameGenerator}.
|
* <p>The default is a {@link AnnotationBeanNameGenerator}.
|
||||||
*/
|
*/
|
||||||
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
|
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
|
||||||
this.beanNameGenerator = (beanNameGenerator != null ?
|
this.beanNameGenerator = (beanNameGenerator != null ? beanNameGenerator : new AnnotationBeanNameGenerator());
|
||||||
beanNameGenerator : new AnnotationBeanNameGenerator());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -91,11 +98,10 @@ public class AnnotatedBeanDefinitionReader {
|
||||||
* <p>The default is an {@link AnnotationScopeMetadataResolver}.
|
* <p>The default is an {@link AnnotationScopeMetadataResolver}.
|
||||||
*/
|
*/
|
||||||
public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver) {
|
public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver) {
|
||||||
this.scopeMetadataResolver = (scopeMetadataResolver != null ?
|
this.scopeMetadataResolver = (scopeMetadataResolver != null ? scopeMetadataResolver
|
||||||
scopeMetadataResolver : new AnnotationScopeMetadataResolver());
|
: new AnnotationScopeMetadataResolver());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void register(Class<?>... annotatedClasses) {
|
public void register(Class<?>... annotatedClasses) {
|
||||||
for (Class<?> annotatedClass : annotatedClasses) {
|
for (Class<?> annotatedClass : annotatedClasses) {
|
||||||
registerBean(annotatedClass);
|
registerBean(annotatedClass);
|
||||||
|
|
@ -127,11 +133,9 @@ public class AnnotatedBeanDefinitionReader {
|
||||||
for (Class<? extends Annotation> qualifier : qualifiers) {
|
for (Class<? extends Annotation> qualifier : qualifiers) {
|
||||||
if (Primary.class.equals(qualifier)) {
|
if (Primary.class.equals(qualifier)) {
|
||||||
abd.setPrimary(true);
|
abd.setPrimary(true);
|
||||||
}
|
} else if (Lazy.class.equals(qualifier)) {
|
||||||
else if (Lazy.class.equals(qualifier)) {
|
|
||||||
abd.setLazyInit(true);
|
abd.setLazyInit(true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
abd.addQualifier(new AutowireCandidateQualifier(qualifier));
|
abd.addQualifier(new AutowireCandidateQualifier(qualifier));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
public @interface Profile {
|
public @interface Profile {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The set profiles for which this component should be registered.
|
* The set of profiles for which this component should be registered.
|
||||||
*/
|
*/
|
||||||
String[] value();
|
String[] value();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue