Skip to content

Commit

Permalink
ConfigurationClassUtils should check bean methods in super classes
Browse files Browse the repository at this point in the history
  • Loading branch information
quaff committed May 10, 2023
1 parent 993a69d commit 5b4f2eb
Showing 1 changed file with 12 additions and 5 deletions.
Expand Up @@ -48,6 +48,7 @@
* @author Juergen Hoeller
* @author Sam Brannen
* @author Stephane Nicoll
* @author Yanming Zhou
* @since 6.0
*/
public abstract class ConfigurationClassUtils {
Expand Down Expand Up @@ -136,7 +137,7 @@ else if (beanDef instanceof AbstractBeanDefinition abstractBd && abstractBd.hasB
if (config != null && !Boolean.FALSE.equals(config.get("proxyBeanMethods"))) {
beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_FULL);
}
else if (config != null || isConfigurationCandidate(metadata)) {
else if (config != null || isConfigurationCandidate(metadata, metadataReaderFactory)) {
beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_LITE);
}
else {
Expand All @@ -156,10 +157,11 @@ else if (config != null || isConfigurationCandidate(metadata)) {
* Check the given metadata for a configuration class candidate
* (or nested component class declared within a configuration/component class).
* @param metadata the metadata of the annotated class
* @param metadataReaderFactory the current factory in use by the caller
* @return {@code true} if the given class is to be registered for
* configuration class processing; {@code false} otherwise
*/
static boolean isConfigurationCandidate(AnnotationMetadata metadata) {
static boolean isConfigurationCandidate(AnnotationMetadata metadata, MetadataReaderFactory metadataReaderFactory) {
// Do not consider an interface or an annotation...
if (metadata.isInterface()) {
return false;
Expand All @@ -173,12 +175,17 @@ static boolean isConfigurationCandidate(AnnotationMetadata metadata) {
}

// Finally, let's look for @Bean methods...
return hasBeanMethods(metadata);
return hasBeanMethods(metadata, metadataReaderFactory);
}

static boolean hasBeanMethods(AnnotationMetadata metadata) {
static boolean hasBeanMethods(AnnotationMetadata metadata, MetadataReaderFactory metadataReaderFactory) {
try {
return metadata.hasAnnotatedMethods(Bean.class.getName());
boolean result = metadata.hasAnnotatedMethods(Bean.class.getName());
if (!result && metadata.hasSuperClass()) {
metadata = metadataReaderFactory.getMetadataReader(metadata.getSuperClassName()).getAnnotationMetadata();
result = metadata.hasAnnotatedMethods(Bean.class.getName());
}
return result;
}
catch (Throwable ex) {
if (logger.isDebugEnabled()) {
Expand Down

0 comments on commit 5b4f2eb

Please sign in to comment.