I am trying to create a pointcut for an abstract method implemented in the child class, but the AOP never gets called.
Here is my Minimal Java Code:
package com.example;
public class Service {
private ParentAbstractClass clazz;
public Service(ParentAbstractClass clazz) {
this.clazz = clazz;
}
public void process() {
clazz.method();
}
}
This is the service class which has an abstraction of the Class to be injected and it calls a method.
My abstract class which has some common logic and an Implementation specific code which is an abstract method.
package com.example;
import java.util.List;
public abstract class ParentAbstractClass {
public void method() {
abstractMethod(List.of("test"));
}
public abstract void abstractMethod(List<String> names);
}
This is the class which provides an implementation for the abstract method.
package com.example;
import java.util.List;
public class ConcreteClass extends ParentAbstractClass {
@Override
public void abstractMethod(List<String> names) {
System.out.println("Look up! AOP should have executed");
}
}
With this setup, I am using spring XML to configure my beans.
<bean id = "clazz" class="com.example.ConcreteClass"/>
<bean id="myservice" class="com.example.Service">
<constructor-arg ref="clazz"/>
</bean>
<bean id = "aspect" class="com.exmple.TxAspect"/>
<aop:config>
<aop:aspect id="mergeEnableAspect" ref="aspect">
<aop:pointcut id="mergeServicePointCut"
expression="execution(* com.example.ConcreteClass.abstractMethod(..))"/>
<aop:around pointcut-ref="mergeServicePointCut" method="test" arg-names="pjp"/>
</aop:aspect>
</aop:config>
And finally the AOP class:
import org.aspectj.lang.ProceedingJoinPoint;
public class TxAspect {
public void test(ProceedingJoinPoint pjp) {
System.out.println("I am not going to do anything");
}
}
In my abstractMethod
I am doing something which is transactional in nature and I have business need of controlling the transactions manually but, My aspect class never gets invoked. Can someone please help me out to figure out what mistake I have done.
Thank you.