detect @Bean methods on registered plain bean classes as well (SPR-5795)
This commit is contained in:
parent
38110d35d2
commit
b8c1130eec
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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>();
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue