Question

How do I write a Spring @AspectJ point-cut (@Pointcut) expression that matches all public methods in a class, regardless of their argument list?

I want an aspect that has @AfterThrowing point-cuts for all the public methods of a particular class that have a particular annotation, @MyAnnotation (similar to what someone else wanted in a previous SO question). At present my aspect is like this:

 @Aspect
 public final class ServiceDataAccessExceptionReporter {

    @Pointcut("execution(public * com.example.Service.*(..)) && @annotation(com.example.MyAnnotation))")
    public void annotatedMethod() {}

    @AfterThrowing(pointcut = "annotatedMethod()", throwing = "exception")
    public void reportException(final DataAccessException exception) {
       ...
    }
 }

The Eclipse Spring plug-in indicates (using arrow annotations in the source-code windows) this as correctly advising a method com.example.Service.getNames(). But it does not indicate that methods that have arguments, such as com.example.Service.getTimes(String name), have been advised.

Is that because the method with the @Pointcut annotation has no arguments? How can I make the point-cut be all methods, regardless of their argument list? Or must I have a separate @Pointcut for each kind of argument list in my com.example.Service class?

Était-ce utile?

La solution

Testing the resulting WAR shows that the aspect is, in fact working, and that all the methods of my service class that I want to be point cuts are point cuts.

I conclude that this is actually a flaw in the Eclipse Spring plug-in: it does not show all the join points when a @Pointcut matches multiple locations, but instead shows only one, which it chooses somewhat arbitrarily.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top