diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java index b60a03cccf..e12d9f150e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java @@ -169,7 +169,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac */ protected static class AspectJAnnotation { - private static final String[] EXPRESSION_PROPERTIES = new String[] {"value", "pointcut"}; + private static final String[] EXPRESSION_ATTRIBUTES = new String[] {"pointcut", "value"}; private static Map, AspectJAnnotationType> annotationTypeMap = new HashMap, AspectJAnnotationType>(8); @@ -198,36 +198,29 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac // but need to invoke them reflectively as there isn't a common interface. try { this.pointcutExpression = resolveExpression(annotation); - this.argumentNames = (String) annotation.getClass().getMethod("argNames").invoke(annotation); + this.argumentNames = (String) AnnotationUtils.getValue(annotation, "argNames"); } catch (Exception ex) { - throw new IllegalArgumentException(annotation + " cannot be an AspectJ annotation", ex); + throw new IllegalArgumentException(annotation + " is not a valid AspectJ annotation", ex); } } private AspectJAnnotationType determineAnnotationType(A annotation) { - for (Class type : annotationTypeMap.keySet()) { - if (type.isInstance(annotation)) { - return annotationTypeMap.get(type); - } + AspectJAnnotationType type = annotationTypeMap.get(annotation.annotationType()); + if (type != null) { + return type; } - throw new IllegalStateException("Unknown annotation type: " + annotation.toString()); + throw new IllegalStateException("Unknown annotation type: " + annotation); } - private String resolveExpression(A annotation) throws Exception { - String expression = null; - for (String methodName : EXPRESSION_PROPERTIES) { - try { - Method method = annotation.getClass().getDeclaredMethod(methodName); - String candidate = (String) method.invoke(annotation); - if (StringUtils.hasText(candidate)) { - expression = candidate; - } - } - catch (NoSuchMethodException ex) { + private String resolveExpression(A annotation) { + for (String attributeName : EXPRESSION_ATTRIBUTES) { + String candidate = (String) AnnotationUtils.getValue(annotation, attributeName); + if (StringUtils.hasText(candidate)) { + return candidate; } } - return expression; + throw new IllegalStateException("Failed to resolve expression: " + annotation); } public AspectJAnnotationType getAnnotationType() { diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 971568dab0..353457c31d 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -1370,6 +1370,9 @@ public abstract class AnnotationUtils { ReflectionUtils.makeAccessible(method); return method.invoke(annotation); } + catch (NoSuchMethodException ex) { + return null; + } catch (InvocationTargetException ex) { rethrowAnnotationConfigurationException(ex.getTargetException()); throw new IllegalStateException(