2016-03-14 24 views
1

我在我們的應用程序中爲2個不同的包配置了Spring AOP來記錄異常。 有用於每個包裝件2種不同的配置:意外地調用了Spring AOP

<aop:config> 
    <aop:aspect id="aspectLoggging" ref="abcExceptionAspect"> 
     <aop:pointcut id="pointCut" 
      expression="execution(* com.abc.*.*(..))" /> 
     <aop:before method="logBefore" pointcut-ref="pointCut" /> 
     <aop:after-throwing method="logExceptionABC" 
      throwing="error" pointcut-ref="pointCut" /> 
     <aop:after method="logAfter" pointcut-ref="pointCut" /> 
    </aop:aspect> 
</aop:config> 

<aop:config> 
    <aop:aspect id="aspectLoggging" ref="xyzlogAspect"> 
     <aop:pointcut id="pointCut" 
      expression="execution(* com.xyz.*.*(..))" /> 
     <aop:before method="logBefore" pointcut-ref="pointCut" /> 
     <aop:after method="logAfter" pointcut-ref="pointCut" /> 
     <aop:after-throwing method="logExceptionXYZ" 
      throwing="error" pointcut-ref="pointCut" /> 
    </aop:aspect> 
</aop:config> 

在服務的方法調用,存在於屬於每個這些包中的類的方法調用:

公共無效方法() {

method1(); - > package abc

method2(); - >包的xyz

}

一些例外在method2的調用logExceptionXYZ方法,其中,我們它包裹在一個通用的異常,說ExceptionXYZ,進一步投擲它發生。

但是,在這之後,logExceptionABC方法也會被調用並拋出一個泛型異常,例如ExceptionABC。

我無法理解爲什麼logExceptionABC方法被調用?

請讓我知道,如果有人知道這樣的問題!

問候, 拉胡爾

+0

'aop:aspect id'和'aop:pointcut id'正在使用相同的ID。我懷疑這可能是問題所在。您可能想嘗試使用唯一的ID。 –

+0

@MadhusudanaReddySunnapu - 我已經注意到相同的aop:aspect id's,並試圖改變它,但沒有奏效。我錯過了aop:切入點id也是一樣的,改變它後問題解決了。感謝您指出! – Rahul

+0

很高興幫助。 –

回答

1

id被分配給該aop:aspect標籤。與aop:pointcut標籤類似的情況也是如此。

嘗試分配唯一的ID。