File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Spring Aspect Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring Aspect Question" Watch "Spring Aspect Question" New topic

Spring Aspect Question

Jeremy Odell

Joined: Mar 30, 2011
Posts: 4
I am in the process of using the @AfterReturning advice. I have set this up to be used for an annotation I have created. The advice looks like:

Now I have set up my Annotation to have certain parameters set. I would like to use these in the above advice.

How do I pass in the annotation?

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Hi Jeremy.

Using the @Annotation designator or, if it is an argument that is annotated, then the @Args, or if it is the target that is Annotated then @Target.

In your case it would be @Annotation, so in your Pointcut Expression you add the @Annotation designator with an "and" or "&&"


execution(@com.rbs.etspii.aspects.CheckAssetType com.rbs.base.common.RBSValidationResult submit*(..)) && @Annotation(assetType)"

Now in your advice method you can have the parameter
myAdviceMethod(ResultType result, CheckAssetType assetType)

Like this taken from the SpringFramework documentation

And then the advice that matches the execution of @Auditable methods:


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Jeremy Odell

Joined: Mar 30, 2011
Posts: 4
Thanks Mark, that was it.

I agree. Here's the link:
subject: Spring Aspect Question
It's not a secret anymore!