I am trying save some data after and whenever a getResponse() is called from an implementation of class DefaultRequestHandler. But this not work, what am I missing?
@Aspect
public abstract class RequestHandler {
protected ServiceProvider response;
protected ServiceProvider request;
@Pointcut
public abstract ServiceProvider getResponse();
@After("com.mypackage.RequestHandler.getResponse()")
public void save(ServiceProvider request, ServiceProvider response){
persistence.save(request, response);
}
}
Feels like you are using a canon to shoot a bug. Just create a base method which first saves and afterwards calls an abstract method. Subclasses need to implement that method.
A solution without AOP and which will still work. You might want to make the save method also final (or private depending on your needs).