Question

What is the format problem with this pointcut?

@Around("execution(* @myPackage.SafetyCritical.*(*))&& @annotation(deny)")

.i forgot to add: exception is "Pointcut is not well-formed: expecting 'name pattern' (last closing bracket before &&)

for an example the pointcut should work with this class:

@SafetyCritical
public class SecureClass
{

    public SecureClass(){

    }
    @Deny
    public void isNotAllowed(){
        System.out.println("This should not happen");

    }

    @Allow
    public void isAllowed(){
        System.out.println("Allowed");

    }

}
Was it helpful?

Solution

EDIT:

I think the pointcut expression you are looking for would be more like this:

@Around("@target(myPackage.SafetyCritical) && @annotation(denyPackage.Deny)")

The @target designator is used to match classes that are marked with the given annoation, and the @annotation designator will filter to the methods annotated with the denyPackage.Deny annotation.

Again, a look through the Spring Documentation regarding AspectJ support would be helpful.

ORIGINAL:

To match on any number of arguments, the parameters definition passed to the execution pointcut designator should be '..'

@Around("execution(* myPackage.SafetyCritical.*(..)) && @annotation(deny)")

The Spring documentation has some examples of using this to denote accepting any number of arguments.

Also, I would venture to guess that that having the '@' symbol in front of your package name is not acceptable. You should remove it.

OTHER TIPS

I've used a pointcut definition like this to match annotated methods:

@Around("execution(@myPackage.SafetyCritical * *(..)) && @annotation(deny)")

The last part @annotation(deny) (like you already know, but some others may not) is to bind the annotation to the advice method argument named "deny".

Edit: As per your update, I was not aware that SafetyCritical was an annotation on the class. I suppose that would be witin the target() goal then:

@Around("execution(* *(..)) && @target(myPackage.SafetyCritical) && @annotation(deny)")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top