Hi,
I'm trying to realise a logging of the current user action.
For that I defined an anspect that logs each method called in a certain package.
The methods can be annotated with @UserTrace to add more information to the current action.
Everything works well except that I just can't get the annotation information from the method. Within the Aspectmethod no annotation is present.
Simple reflections tests without using aspects proofed, that there are annotations and that its working.
So the question is - why are no annotations present within an aspect?
My Web-Application uses: Spring 2.5.6 and Spring WebFlow 2.0.8
Aspect WorkTrace
Annotation UserTraceCode:@Aspect public class WorkTrace { @Around("execution(* de.xxx.web.backingbeans.*.*(..))") public Object logCurrentWork(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{ final Logger log = Logger.getLogger(proceedingJoinPoint.getTarget().getClass()); Signature sig = proceedingJoinPoint.getSignature(); String infoStep = ""; String infoDesc = ""; if(sig instanceof MethodSignature){ MethodSignature mSig = (MethodSignature)sig; Method method = mSig.getMethod(); /* following doesnt work - says there is no annotation */ if(method.isAnnotationPresent(UserTrace.class)){ UserTrace ut = method.getAnnotation(UserTrace.class); infoStep = ut.stepName(); infoDesc = ut.stepDescription(); } } final String methodName = sig.getName(); log.info("WORKTRACE:: "+methodName+" STEP: "+infoStep+" INFO: "+infoDesc); Object returnValue = proceedingJoinPoint.proceed(); return returnValue; } }
matching codepartCode:@Target(value=ElementType.METHOD) @Retention(value=RetentionPolicy.RUNTIME) public @interface UserTrace { public String stepName(); public String stepDescription(); }
works without aspectCode:@Secured(value={"ROLE_ADMIN"}) @UserTrace(stepName="Speicher oder Updaten eines Hauptbereichs",stepDescription="n.a.") public void saveOrUpdateBackEndArea(SoBackEndArea bea){ /* ...do some things ... */ }
Code:Method mme = me.getMethod("saveOrUpdateBackEndArea", SoBackEndArea.class); if(mme.isAnnotationPresent(UserTrace.class)){ UserTrace rA = mme.getAnnotation(UserTrace.class); logger.info("--> "+rA.stepName()); } Annotation[] allAnnotations = mme.getAnnotations(); for (int i = 0; i < allAnnotations.length; i++) { Annotation a = allAnnotations[i]; Class aClass = a.annotationType(); logger.info("x -Annotation: "+a.getClass().getName()+" -> "+aClass.getName()); }
Has anyone an idea why it's not possible to access annotations within the aspectcode ?!?
Greetz - Jan


Reply With Quote
