Restrict nested configuration class introspection to component types
Issue: SPR-16839
This commit is contained in:
@@ -76,6 +76,7 @@ import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -261,8 +262,10 @@ class ConfigurationClassParser {
|
||||
protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass)
|
||||
throws IOException {
|
||||
|
||||
// Recursively process any member (nested) classes first
|
||||
processMemberClasses(configClass, sourceClass);
|
||||
if (sourceClass.getMetadata().isAnnotated(Component.class.getName())) {
|
||||
// Recursively process any member (nested) classes first
|
||||
processMemberClasses(configClass, sourceClass);
|
||||
}
|
||||
|
||||
// Process any @PropertySource annotations
|
||||
for (AnnotationAttributes propertySource : AnnotationConfigUtils.attributesForRepeatable(
|
||||
|
||||
@@ -119,7 +119,7 @@ abstract class ConfigurationClassUtils {
|
||||
beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_LITE);
|
||||
}
|
||||
else {
|
||||
return hasNestedConfigurationClass(metadata, metadataReaderFactory);
|
||||
return false;
|
||||
}
|
||||
|
||||
// It's a full or lite configuration candidate... Let's determine the order value, if any.
|
||||
@@ -131,40 +131,6 @@ abstract class ConfigurationClassUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the specified class declares a nested configuration class.
|
||||
*/
|
||||
private static boolean hasNestedConfigurationClass(
|
||||
AnnotationMetadata metadata, MetadataReaderFactory metadataReaderFactory) {
|
||||
|
||||
// Potentially nested configuration classes...
|
||||
if (metadata instanceof StandardAnnotationMetadata) {
|
||||
Class<?> beanClass = ((StandardAnnotationMetadata) metadata).getIntrospectedClass();
|
||||
for (Class<?> memberClass : beanClass.getDeclaredClasses()) {
|
||||
if (isConfigurationCandidate(new StandardAnnotationMetadata(memberClass))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (String memberName : metadata.getMemberClassNames()) {
|
||||
try {
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(memberName);
|
||||
if (isConfigurationCandidate(metadataReader.getAnnotationMetadata())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not find class file for introspecting configuration annotations: " +
|
||||
memberName, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the given metadata for a configuration class candidate
|
||||
* (or nested component class declared within a configuration/component class).
|
||||
|
||||
Reference in New Issue
Block a user