Good morning,
I have defined a custom annotation that I want to use to mark some classes as Auditable
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Auditable {
}
And have declared an aspect to handle all classes marked with this annotation. I am using AspectJ with Eclipse
@Aspect
public class AuditableClassAspect extends AbstractAuditableAspect {
@Autowired
private ApplicationContext applicationContext;
// Makes the bean auditable
@DeclareMixin(value="@Auditable *")
public Auditable auditableBeanFactory(Object instance) {
// Use a bean delegator as a mixin object
Auditable mixin = applicationContext.getBean(PersistentDelegate.class);
mixin.setObject(instance);
return mixin;
}
@Pointcut("get(* (@Auditable *).*) && this(object)")
public void executionGet(Object object) {}
@Pointcut("set(* (@Auditable *).*) && this(object)")
public void executionSet(Object object) {}
}
Then I have marked a class:
@Auditable
public class Report implements Serializable {
private static final long serialVersionUID = 4746372287860486647L;
private String companyName;
private Date reportingDate;
I am using AspectJ with Spring, and have defined the Aspect in applicationContext.xml
<bean class="com.xxx.aop.AuditableClassAspect" factory-method="aspectOf" />
My issue is that there is no matching happening. The Aspect doesn't "detect" the Report class as an Auditable class.
In eclipse it doesn't show any matching. At run time I have an exception when I am casting my report in an Auditable interface.
Do you have any idea what there is no match?
For information, if in my code I write @DeclareMixin(value="com.xxx.Report") Then I have a matching and the Aspect works. Is there something missing with the annotation?
Thanks
Gilles