Search code examples
javaspringpointcuts

Pointcut not well Formatted


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");

    }

}

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.