2013-04-22 1 views
0

메소드에 타이머를 추가하기 위해 코스튬 어노테이션이있는 AOP를 사용하고 있습니다.aop을 사용하여 예외 처리

@Around(value = "@annotation(benchmark)") 
    public void func(final ProceedingJoinPoint joinPoint, final Benchmark benchmark) throws Throwable { 
     //wrap the call to the method with timer 
     final long t0 = System.currentTimeMillis(); 
     logger.error(t0 + " "); 
     joinPoint.proceed(); 
     final long elapsed = (System.currentTimeMillis() - t0); 
     logger.error(elapsed + " "); 
    } 

주석이 달린 메소드에서 예외가 발생하면 무엇인가 할 수 있기를 원합니다. 내가 올바른 방법이 무엇인지 잘 모르겠습니다 ...

내가 읽고 있다는 것을 보았다 :

@AfterThrowing(pointcut = "execution(* com.mycompany.package..* (..))", throwing = "ex") 

지금까지 내가 @AfterThrowing 내가, 내가 필요로 원하는 걸 포기하지 않는 이해 어떻게 든 벤치 마크 주석으로 주석 처리 된 메소드에서만 예외를 캐시합니다.

아이디어가 있으십니까?

감사합니다.

답변

2

excecution에 당신은 당신이 예를 들어 잡으려고 할 주석을 지정할 수 있습니다 : 오류가 다음 FUNC 방법이라고 com.mycompany.package 클래스 메서드에서 던지는 경우

@AfterThrowing(pointcut = "execution(@org.aspectj.lang.annotation.Around * com.mycompany.package..* (..))", throwing = "ex") 
0
<aop:config> 
     <aop:aspect id="testInterceptor" ref="testid"> 
      <aop:pointcut expression="execution(* com.mycompany.package..* (..))" 
       id="pointcutid" /> 

      <aop:after-throwing pointcut-ref="pointcutid" 
       throwing="err" method="func" /> 


     </aop:aspect> 
    </aop:config> 


<bean id="testid" class="com.XXX.XXX.ClassNameHavingfuncMethod"> </bean> 

.