Perf4j没有配置带注释的接口方法

时间:2013-02-11 21:30:06

标签: java spring annotations perf4j

我有以下界面和类

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>

当我serviceA.getString()时,TimingAspect没有截获该呼叫。如果我将注释从接口移动到实现类,它会被拦截。我看到的原因是方法级别注释不是继承的。怎么解决这个?写一些CustomBeanAnnotationProcessor

1 个答案:

答案 0 :(得分:0)

即使@Profiled使用@Inherit,它也不会起作用,因为继承的注释只会被传递给子类而不是接口的实现。

  

@Inherited注释在用于注释时不会被继承   除了类型之外的任何东西。实现一个或多个的类型   接口永远不会从接口继承任何注释   实现

来源:http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations.html#annotation-inheritance

更多详情:http://www.jroller.com/melix/entry/the_truth_about_annotations_inheritance

您的自定义处理器会做什么,查询@Profiled的服务界面?我建议您手动注释服务实现,因为根据我的经验@Profiled仅在您使用tagmessage属性(我认为每个实现类不同)时才有用。 / p>

http://perf4j.codehaus.org/devguide.html#Adding_the_Profiled_Annotation_to_Method_Declarations - &gt; “@Profiled(tag =”dynamicTag _ {$ 0}“)”