|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
* Copyright 2002-2021 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. |
|
|
@ -36,7 +36,7 @@ import org.springframework.util.ClassUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Represents a user-defined {@link Configuration @Configuration} class. |
|
|
|
* Represents a user-defined {@link Configuration @Configuration} class. |
|
|
|
* Includes a set of {@link Bean} methods, including all such methods |
|
|
|
* <p>Includes a set of {@link Bean} methods, including all such methods |
|
|
|
* defined in the ancestry of the class, in a 'flattened-out' manner. |
|
|
|
* defined in the ancestry of the class, in a 'flattened-out' manner. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Chris Beams |
|
|
|
* @author Chris Beams |
|
|
@ -74,7 +74,7 @@ final class ConfigurationClass { |
|
|
|
* @param beanName must not be {@code null} |
|
|
|
* @param beanName must not be {@code null} |
|
|
|
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass) |
|
|
|
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ConfigurationClass(MetadataReader metadataReader, String beanName) { |
|
|
|
ConfigurationClass(MetadataReader metadataReader, String beanName) { |
|
|
|
Assert.notNull(beanName, "Bean name must not be null"); |
|
|
|
Assert.notNull(beanName, "Bean name must not be null"); |
|
|
|
this.metadata = metadataReader.getAnnotationMetadata(); |
|
|
|
this.metadata = metadataReader.getAnnotationMetadata(); |
|
|
|
this.resource = metadataReader.getResource(); |
|
|
|
this.resource = metadataReader.getResource(); |
|
|
@ -89,7 +89,7 @@ final class ConfigurationClass { |
|
|
|
* @param importedBy the configuration class importing this one or {@code null} |
|
|
|
* @param importedBy the configuration class importing this one or {@code null} |
|
|
|
* @since 3.1.1 |
|
|
|
* @since 3.1.1 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ConfigurationClass(MetadataReader metadataReader, @Nullable ConfigurationClass importedBy) { |
|
|
|
ConfigurationClass(MetadataReader metadataReader, @Nullable ConfigurationClass importedBy) { |
|
|
|
this.metadata = metadataReader.getAnnotationMetadata(); |
|
|
|
this.metadata = metadataReader.getAnnotationMetadata(); |
|
|
|
this.resource = metadataReader.getResource(); |
|
|
|
this.resource = metadataReader.getResource(); |
|
|
|
this.importedBy.add(importedBy); |
|
|
|
this.importedBy.add(importedBy); |
|
|
@ -101,7 +101,7 @@ final class ConfigurationClass { |
|
|
|
* @param beanName name of the {@code @Configuration} class bean |
|
|
|
* @param beanName name of the {@code @Configuration} class bean |
|
|
|
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass) |
|
|
|
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ConfigurationClass(Class<?> clazz, String beanName) { |
|
|
|
ConfigurationClass(Class<?> clazz, String beanName) { |
|
|
|
Assert.notNull(beanName, "Bean name must not be null"); |
|
|
|
Assert.notNull(beanName, "Bean name must not be null"); |
|
|
|
this.metadata = AnnotationMetadata.introspect(clazz); |
|
|
|
this.metadata = AnnotationMetadata.introspect(clazz); |
|
|
|
this.resource = new DescriptiveResource(clazz.getName()); |
|
|
|
this.resource = new DescriptiveResource(clazz.getName()); |
|
|
@ -116,7 +116,7 @@ final class ConfigurationClass { |
|
|
|
* @param importedBy the configuration class importing this one (or {@code null}) |
|
|
|
* @param importedBy the configuration class importing this one (or {@code null}) |
|
|
|
* @since 3.1.1 |
|
|
|
* @since 3.1.1 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ConfigurationClass(Class<?> clazz, @Nullable ConfigurationClass importedBy) { |
|
|
|
ConfigurationClass(Class<?> clazz, @Nullable ConfigurationClass importedBy) { |
|
|
|
this.metadata = AnnotationMetadata.introspect(clazz); |
|
|
|
this.metadata = AnnotationMetadata.introspect(clazz); |
|
|
|
this.resource = new DescriptiveResource(clazz.getName()); |
|
|
|
this.resource = new DescriptiveResource(clazz.getName()); |
|
|
|
this.importedBy.add(importedBy); |
|
|
|
this.importedBy.add(importedBy); |
|
|
@ -128,7 +128,7 @@ final class ConfigurationClass { |
|
|
|
* @param beanName name of the {@code @Configuration} class bean |
|
|
|
* @param beanName name of the {@code @Configuration} class bean |
|
|
|
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass) |
|
|
|
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ConfigurationClass(AnnotationMetadata metadata, String beanName) { |
|
|
|
ConfigurationClass(AnnotationMetadata metadata, String beanName) { |
|
|
|
Assert.notNull(beanName, "Bean name must not be null"); |
|
|
|
Assert.notNull(beanName, "Bean name must not be null"); |
|
|
|
this.metadata = metadata; |
|
|
|
this.metadata = metadata; |
|
|
|
this.resource = new DescriptiveResource(metadata.getClassName()); |
|
|
|
this.resource = new DescriptiveResource(metadata.getClassName()); |
|
|
@ -136,19 +136,19 @@ final class ConfigurationClass { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AnnotationMetadata getMetadata() { |
|
|
|
AnnotationMetadata getMetadata() { |
|
|
|
return this.metadata; |
|
|
|
return this.metadata; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Resource getResource() { |
|
|
|
Resource getResource() { |
|
|
|
return this.resource; |
|
|
|
return this.resource; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getSimpleName() { |
|
|
|
String getSimpleName() { |
|
|
|
return ClassUtils.getShortName(getMetadata().getClassName()); |
|
|
|
return ClassUtils.getShortName(getMetadata().getClassName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setBeanName(String beanName) { |
|
|
|
void setBeanName(String beanName) { |
|
|
|
this.beanName = beanName; |
|
|
|
this.beanName = beanName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -171,7 +171,7 @@ final class ConfigurationClass { |
|
|
|
* Merge the imported-by declarations from the given configuration class into this one. |
|
|
|
* Merge the imported-by declarations from the given configuration class into this one. |
|
|
|
* @since 4.0.5 |
|
|
|
* @since 4.0.5 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void mergeImportedBy(ConfigurationClass otherConfigClass) { |
|
|
|
void mergeImportedBy(ConfigurationClass otherConfigClass) { |
|
|
|
this.importedBy.addAll(otherConfigClass.importedBy); |
|
|
|
this.importedBy.addAll(otherConfigClass.importedBy); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -181,35 +181,35 @@ final class ConfigurationClass { |
|
|
|
* @since 4.0.5 |
|
|
|
* @since 4.0.5 |
|
|
|
* @see #isImported() |
|
|
|
* @see #isImported() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Set<ConfigurationClass> getImportedBy() { |
|
|
|
Set<ConfigurationClass> getImportedBy() { |
|
|
|
return this.importedBy; |
|
|
|
return this.importedBy; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addBeanMethod(BeanMethod method) { |
|
|
|
void addBeanMethod(BeanMethod method) { |
|
|
|
this.beanMethods.add(method); |
|
|
|
this.beanMethods.add(method); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Set<BeanMethod> getBeanMethods() { |
|
|
|
Set<BeanMethod> getBeanMethods() { |
|
|
|
return this.beanMethods; |
|
|
|
return this.beanMethods; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addImportedResource(String importedResource, Class<? extends BeanDefinitionReader> readerClass) { |
|
|
|
void addImportedResource(String importedResource, Class<? extends BeanDefinitionReader> readerClass) { |
|
|
|
this.importedResources.put(importedResource, readerClass); |
|
|
|
this.importedResources.put(importedResource, readerClass); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addImportBeanDefinitionRegistrar(ImportBeanDefinitionRegistrar registrar, AnnotationMetadata importingClassMetadata) { |
|
|
|
void addImportBeanDefinitionRegistrar(ImportBeanDefinitionRegistrar registrar, AnnotationMetadata importingClassMetadata) { |
|
|
|
this.importBeanDefinitionRegistrars.put(registrar, importingClassMetadata); |
|
|
|
this.importBeanDefinitionRegistrars.put(registrar, importingClassMetadata); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Map<ImportBeanDefinitionRegistrar, AnnotationMetadata> getImportBeanDefinitionRegistrars() { |
|
|
|
Map<ImportBeanDefinitionRegistrar, AnnotationMetadata> getImportBeanDefinitionRegistrars() { |
|
|
|
return this.importBeanDefinitionRegistrars; |
|
|
|
return this.importBeanDefinitionRegistrars; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Class<? extends BeanDefinitionReader>> getImportedResources() { |
|
|
|
Map<String, Class<? extends BeanDefinitionReader>> getImportedResources() { |
|
|
|
return this.importedResources; |
|
|
|
return this.importedResources; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void validate(ProblemReporter problemReporter) { |
|
|
|
void validate(ProblemReporter problemReporter) { |
|
|
|
// A configuration class may not be final (CGLIB limitation) unless it declares proxyBeanMethods=false
|
|
|
|
// A configuration class may not be final (CGLIB limitation) unless it declares proxyBeanMethods=false
|
|
|
|
Map<String, Object> attributes = this.metadata.getAnnotationAttributes(Configuration.class.getName()); |
|
|
|
Map<String, Object> attributes = this.metadata.getAnnotationAttributes(Configuration.class.getName()); |
|
|
|
if (attributes != null && (Boolean) attributes.get("proxyBeanMethods")) { |
|
|
|
if (attributes != null && (Boolean) attributes.get("proxyBeanMethods")) { |
|
|
@ -244,7 +244,7 @@ final class ConfigurationClass { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private class FinalConfigurationProblem extends Problem { |
|
|
|
private class FinalConfigurationProblem extends Problem { |
|
|
|
|
|
|
|
|
|
|
|
public FinalConfigurationProblem() { |
|
|
|
FinalConfigurationProblem() { |
|
|
|
super(String.format("@Configuration class '%s' may not be final. Remove the final modifier to continue.", |
|
|
|
super(String.format("@Configuration class '%s' may not be final. Remove the final modifier to continue.", |
|
|
|
getSimpleName()), new Location(getResource(), getMetadata())); |
|
|
|
getSimpleName()), new Location(getResource(), getMetadata())); |
|
|
|
} |
|
|
|
} |
|
|
|