You made several errors:
- When using
<concrete-aspect>
, the concrete pointcut should just be in your aop.xml, not in your code. Maybe it was a copy & paste error, but in your example it looks as if the concrete pointcut was defined twice: in code and in XML. - When concretising an abstract aspect, the abstract aspect must already contain the advice you want to map to the concrete pointcut. It cannot be overridden via XML or via a combination of code and XML.
Look at my own example, quite similar to yours:
Sample application:
package de.scrum_master.app;
public class Application {
public static void main(String[] args) {
Application app = new Application();
app.say("Hello world!");
app.add(11, 22);
}
private int add(int i, int j) { return i + j; }
public void say(String message) { System.out.println(message); }
}
As you can see, there are two public methods (one static, one non-static) and a private method. I did this so as to test if the concrete pointcut later really only catches the public ones.
Abstract aspect:
package de.scrum_master.aspectj;
public abstract aspect AbstractAspect {
protected abstract pointcut publicMethod();
Object around() : publicMethod() {
System.out.println(thisJoinPointStaticPart);
return proceed();
}
}
aop.xml:
<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>
<concrete-aspect
name="de.scrum_master.aspectj.ConcreteAspect"
extends="de.scrum_master.aspectj.AbstractAspect"
>
<pointcut
name="publicMethod"
expression="execution(public * de.scrum_master..*(..))"
/>
</concrete-aspect>
</aspects>
</aspectj>
Application output when using LTW:
execution(void de.scrum_master.app.Application.main(String[]))
execution(void de.scrum_master.app.Application.say(String))
Hello world!