isLiteConfigurationCandidate considers @ComponentScan and @ImportResource as indicators as well
Issue: SPR-11769
This commit is contained in:
parent
89fc3c0257
commit
b4d447fc3d
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,6 +17,8 @@
|
|||
package org.springframework.context.annotation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -46,8 +48,18 @@ abstract class ConfigurationClassUtils {
|
|||
private static final String CONFIGURATION_CLASS_ATTRIBUTE =
|
||||
Conventions.getQualifiedAttributeName(ConfigurationClassPostProcessor.class, "configurationClass");
|
||||
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ConfigurationClassUtils.class);
|
||||
|
||||
private static final Set<String> candidateIndicators = new HashSet<String>(4);
|
||||
|
||||
static {
|
||||
candidateIndicators.add(Component.class.getName());
|
||||
candidateIndicators.add(ComponentScan.class.getName());
|
||||
candidateIndicators.add(Import.class.getName());
|
||||
candidateIndicators.add(ImportResource.class.getName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the given bean definition is a candidate for a configuration class
|
||||
|
@ -119,7 +131,7 @@ abstract class ConfigurationClassUtils {
|
|||
|
||||
/**
|
||||
* Check the given metadata for a lite configuration class candidate
|
||||
* (i.e. a class annotated with {@code @Component} or just having
|
||||
* (e.g. a class annotated with {@code @Component} or just having
|
||||
* {@code @Import} declarations or {@code @Bean methods}).
|
||||
* @param metadata the metadata of the annotated class
|
||||
* @return {@code true} if the given class is to be processed as a lite
|
||||
|
@ -127,8 +139,15 @@ abstract class ConfigurationClassUtils {
|
|||
*/
|
||||
public static boolean isLiteConfigurationCandidate(AnnotationMetadata metadata) {
|
||||
// Do not consider an interface or an annotation...
|
||||
return (!metadata.isInterface() && (metadata.isAnnotated(Component.class.getName()) ||
|
||||
metadata.isAnnotated(Import.class.getName()) || metadata.hasAnnotatedMethods(Bean.class.getName())));
|
||||
if (metadata.isInterface()) {
|
||||
return false;
|
||||
}
|
||||
for (String indicator : candidateIndicators) {
|
||||
if (metadata.isAnnotated(indicator)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return metadata.hasAnnotatedMethods(Bean.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,27 +72,23 @@ public class ComponentScanAndImportAnnotationInteractionTests {
|
|||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("org.springframework.context.annotation.componentscan.simple")
|
||||
static class Config1 {
|
||||
static final class Config1 {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Import(org.springframework.context.annotation.componentscan.simple.SimpleComponent.class)
|
||||
static class Config2 {
|
||||
static final class Config2 {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Import(ImportedConfig.class)
|
||||
static class Config3 {
|
||||
static final class Config3 {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("org.springframework.context.annotation.componentscan.simple")
|
||||
public static class ImportedConfig {
|
||||
public static final class ImportedConfig {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue