From 3e63951a57c10f1de4d736531b4cdcc1c184e980 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 17 Apr 2009 17:32:29 +0000 Subject: [PATCH] relaxed @AspectJ detection check (for CGLIB subclasses to still be recognized as an aspect) --- .../AbstractAspectJAdvisorFactory.java | 5 ++--- .../aspectj/annotation/AspectMetadata.java | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java index fbc82096818..a22602396b6 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java @@ -112,12 +112,11 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac * when compiled by ajc with the -1.5 flag, yet they cannot be consumed by Spring AOP. */ public boolean isAspect(Class clazz) { - return (AjTypeSystem.getAjType(clazz).isAspect() && - hasAspectAnnotation(clazz) && !compiledByAjc(clazz)); + return (hasAspectAnnotation(clazz) && !compiledByAjc(clazz)); } private boolean hasAspectAnnotation(Class clazz) { - return clazz.isAnnotationPresent(Aspect.class); + return (AnnotationUtils.findAnnotation(clazz, Aspect.class) != null); } /** diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectMetadata.java b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectMetadata.java index c239aac599d..cde9f43ef30 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectMetadata.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,13 +67,23 @@ public class AspectMetadata { * @param aspectClass the aspect class * @param aspectName the name of the aspect */ - public AspectMetadata(Class aspectClass, String aspectName) { + public AspectMetadata(Class aspectClass, String aspectName) { this.aspectName = aspectName; - this.ajType = AjTypeSystem.getAjType(aspectClass); - - if (!this.ajType.isAspect()) { + + Class currClass = aspectClass; + AjType ajType = null; + while (!currClass.equals(Object.class)) { + AjType ajTypeToCheck = AjTypeSystem.getAjType(currClass); + if (ajTypeToCheck.isAspect()) { + ajType = ajTypeToCheck; + break; + } + currClass = currClass.getSuperclass(); + } + if (ajType == null) { throw new IllegalArgumentException("Class '" + aspectClass.getName() + "' is not an @AspectJ aspect"); } + this.ajType = ajType; if (this.ajType.getDeclarePrecedence().length > 0) { throw new IllegalArgumentException("DeclarePrecendence not presently supported in Spring AOP"); }