I have the following interface and class
public interface ServiceA {
@Profiled
String getString();
}
public class ServiceAImpl implements ServiceA{
String getString(){
System.out.println("getString");
}
}
<beans ....>
<aop:aspectj-autoproxy />
<bean id="timingAspect" class="org.perf4j.log4j.aop.TimingAspect"/>"
<bean id="serviceA" class="com.naresh.profiler.service.ServiceAImpl" />
</beans>
When I do serviceA.getString() the call was not intercepted by the TimingAspect. It does intercepted if I move the annotation from interface to implementation class. The reason I see is that method level annotations are not inherited. How to solve this? By writing some CustomBeanAnnotationProcessor?
Even if
@Profiledused@Inheritit wouldn’t work because inherited annotations are only ever passed on to sub classed and not implementations of interfaces.Source: http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations.html#annotation-inheritance
More details: http://www.jroller.com/melix/entry/the_truth_about_annotations_inheritance
What would your custom processor do, query a service’s interface for
@Profiled? I suggest you manually annotate the service implementations because in my experience@Profiledis only helpful if you use it with itstagandmessageattributes (which differ in each implementing class I suppose).http://perf4j.codehaus.org/devguide.html#Adding_the_Profiled_Annotation_to_Method_Declarations -> “@Profiled(tag = “dynamicTag_{$0}”)”