2013-02-11 2 views
0

내가 serviceA.getString() 호출이 TimingAspect에 의해 차단되지 않은 작업을 수행 할 때 나는 다음과 같은 인터페이스와 클래스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> 

이를 주석의 프로필하지 않습니다. 어노테이션을 인터페이스에서 구현 클래스로 옮기면 인터셉트됩니다. 내가 보는 이유는 메소드 레벨 주석이 상속되지 않는다는 것입니다. 어떻게 해결할 수 있을까요? 일부 CustomBeanAnnotationProcessor 작성 하시겠습니까?

답변

0

@Profiled@Inherit으로 사용 되더라도 상속 된 주석은 하위 클래스로 전달되고 인터페이스는 구현되지 않기 때문에 작동하지 않습니다.

유형 이외의 주석을 달기 위해 상속 된 주석이 상속되지 않습니다. 하나 이상의 인터페이스를 구현하는 유형은 이 구현하는 인터페이스의 주석을 상속하지 않습니다.

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

자세한 내용 : 사용자 정의 프로세서, @Profiled에 대한 서비스의 인터페이스를 쿼리 어떻게 할 것인지 http://www.jroller.com/melix/entry/the_truth_about_annotations_inheritance

? 내 경험에 의하면 @Profiledtagmessage 속성 (각 구현 클래스마다 다를 수 있음)과 함께 사용하는 경우에만 유용하기 때문에 서비스 구현에 수동으로 주석을 달 것을 제안합니다.

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