【问题标题】:Perf4j does not profile annotated Interface methodPerf4j 不分析带注释的接口方法
【发布时间】:2013-02-11 21:30:05
【问题描述】:

我有如下接口和类

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?

【问题讨论】:

    标签: java spring annotations perf4j


    【解决方案1】:

    即使@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 属性一起使用时才有帮助(我认为每个实现类都不同)。

    http://perf4j.codehaus.org/devguide.html#Adding_the_Profiled_Annotation_to_Method_Declarations -> "@Profiled(tag = "dynamicTag_{$0}")"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-21
      • 1970-01-01
      • 1970-01-01
      • 2014-11-27
      • 1970-01-01
      • 2015-02-15
      • 1970-01-01
      相关资源
      最近更新 更多