Browse Source

Avoid unnecessary annotation introspection on framework methods

Issue: SPR-16933
pull/1946/head
Juergen Hoeller 6 years ago
parent
commit
34052945de
  1. 9
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java
  2. 10
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

9
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java

@ -189,8 +189,8 @@ class ConfigurationClassEnhancer { @@ -189,8 +189,8 @@ class ConfigurationClassEnhancer {
@Override
public int accept(Method method) {
for (int i = 0; i < this.callbacks.length; i++) {
if (!(this.callbacks[i] instanceof ConditionalCallback) ||
((ConditionalCallback) this.callbacks[i]).isMatch(method)) {
Callback callback = this.callbacks[i];
if (!(callback instanceof ConditionalCallback) || ((ConditionalCallback) callback).isMatch(method)) {
return i;
}
}
@ -286,6 +286,10 @@ class ConfigurationClassEnhancer { @@ -286,6 +286,10 @@ class ConfigurationClassEnhancer {
@Override
public boolean isMatch(Method candidateMethod) {
return isSetBeanFactory(candidateMethod);
}
public static boolean isSetBeanFactory(Method candidateMethod) {
return (candidateMethod.getName().equals("setBeanFactory") &&
candidateMethod.getParameterCount() == 1 &&
BeanFactory.class == candidateMethod.getParameterTypes()[0] &&
@ -432,6 +436,7 @@ class ConfigurationClassEnhancer { @@ -432,6 +436,7 @@ class ConfigurationClassEnhancer {
@Override
public boolean isMatch(Method candidateMethod) {
return (candidateMethod.getDeclaringClass() != Object.class &&
!BeanFactoryAwareMethodInterceptor.isSetBeanFactory(candidateMethod) &&
BeanAnnotationHelper.isBeanAnnotated(candidateMethod));
}

10
spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

@ -640,12 +640,14 @@ public abstract class AnnotationUtils { @@ -640,12 +640,14 @@ public abstract class AnnotationUtils {
if (anns.length == 0) {
return false;
}
if (anns.length == 1) {
Class<?> annType = anns[0].annotationType();
return (annType != Nullable.class && annType != Deprecated.class);
}
for (Annotation ann : anns) {
Class<?> annType = ann.annotationType();
if (annType != Nullable.class && annType != Deprecated.class) {
return true;
}
}
return false;
}
private static boolean isOverride(Method method, Method candidate) {
if (!candidate.getName().equals(method.getName()) ||

Loading…
Cancel
Save