detect @Bean methods on registered plain bean classes as well (SPR-5795)

This commit is contained in:
Juergen Hoeller 2009-09-24 10:45:56 +00:00
parent 38110d35d2
commit b8c1130eec
4 changed files with 36 additions and 1 deletions

View File

@ -222,7 +222,8 @@ public class ConfigurationClassPostProcessor implements BeanFactoryPostProcessor
beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_FULL);
return true;
}
else if (metadata.isAnnotated(Component.class.getName())) {
else if (metadata.isAnnotated(Component.class.getName()) ||
metadata.hasAnnotatedMethods(Bean.class.getName())) {
beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_LITE);
return true;
}

View File

@ -83,6 +83,12 @@ public interface AnnotationMetadata extends ClassMetadata {
*/
Map<String, Object> getAnnotationAttributes(String annotationType);
/**
* Determine whether the underlying class has any methods that are
* annotated (or meta-annotated) with the given annotation type.
*/
boolean hasAnnotatedMethods(String annotationType);
/**
* Retrieve the method metadata for all methods that are annotated
* (or meta-annotated) with the given annotation type.

View File

@ -128,6 +128,25 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements
return null;
}
public boolean hasAnnotatedMethods(String annotationType) {
Method[] methods = getIntrospectedClass().getDeclaredMethods();
for (Method method : methods) {
for (Annotation ann : method.getAnnotations()) {
if (ann.annotationType().getName().equals(annotationType)) {
return true;
}
else {
for (Annotation metaAnn : ann.annotationType().getAnnotations()) {
if (metaAnn.annotationType().getName().equals(annotationType)) {
return true;
}
}
}
}
}
return false;
}
public Set<MethodMetadata> getAnnotatedMethods(String annotationType) {
Method[] methods = getIntrospectedClass().getDeclaredMethods();
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>();

View File

@ -100,6 +100,15 @@ final class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor
return this.attributeMap.get(annotationType);
}
public boolean hasAnnotatedMethods(String annotationType) {
for (MethodMetadata method : this.methodMetadataSet) {
if (method.isAnnotated(annotationType)) {
return true;
}
}
return false;
}
public Set<MethodMetadata> getAnnotatedMethods(String annotationType) {
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>();
for (MethodMetadata method : this.methodMetadataSet) {