Browse Source

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

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1984 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 17 years ago
parent
commit
a709d5ffce
  1. 3
      org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java
  2. 6
      org.springframework.core/src/main/java/org/springframework/core/type/AnnotationMetadata.java
  3. 19
      org.springframework.core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java
  4. 9
      org.springframework.core/src/main/java/org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor.java

3
org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

@ -222,7 +222,8 @@ public class ConfigurationClassPostProcessor implements BeanFactoryPostProcessor @@ -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;
}

6
org.springframework.core/src/main/java/org/springframework/core/type/AnnotationMetadata.java

@ -83,6 +83,12 @@ public interface AnnotationMetadata extends ClassMetadata { @@ -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.

19
org.springframework.core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java

@ -128,6 +128,25 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements @@ -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>();

9
org.springframework.core/src/main/java/org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor.java

@ -100,6 +100,15 @@ final class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor @@ -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…
Cancel
Save