2011-05-18 23 views
1

我想測試大量的類以便與Spring Insight一起使用,而不是將@InsightOperation手動添加到方法中,我寫了一個方面來使用切點註釋方法。使用Aspect爲Spring Insight註解使用@InsightOperation的方法

但是,這是行不通的。雖然手動註釋會影響Spring Insight跟蹤日誌記錄,但AspectJ方法不起作用。

有什麼我在這裏做錯了嗎? (我反編譯的類aspectizing後確實發現在類方法的註釋)

這方面的代碼片段:

declare @method :public * com.example.IExample.execute(..) : @InsightOperation;

+0

*(我在aspectizing之後反編譯了類並在類方法中找到註解*我理解正確:註釋存在於類文件中,但它仍然不起作用 – 2011-05-18 15:36:00

+0

@Sean這是正確的 – Vishal 2011-05-18 16:10:48

+0

難道加載時間編織(這是Spring Insight使用的)會忽略或無法檢測到編譯時間方面添加的註釋嗎? – Vishal 2011-05-18 18:07:35

回答

0

Spring文檔中這樣說:

使用@ Insight *註釋是可選的 。他們很容易讓最終用戶 定義自定義操作 幀和結束點,而無需 創建插件。由於終端用戶 代碼修改是需要使用 註釋,他們是誰不能或不願 寫方面用戶的選擇 。

http://static.springsource.com/projects/tc-server/2.5/devedition/htmlsingle/devedition.html

如此看來唯一的辦法是寫一個自定義插件

http://static.springsource.com/projects/tc-server/2.5/devedition/htmlsingle/devedition.html#tutorial-plugin

0

這可能是在Insight LTW不拿起你的介紹說明。我將不得不深入研究。

在此期間,你可以嘗試更多的低級別的註釋:

com.springsource.insight.collection.method.MethodOperationsCollected 

如果你看一下彈簧核心插件,你會看到它有類似的功能:

public aspect RepositoryMethodOperationCollectionAspect { 
     declare @type: @Repository * : @MethodOperationsCollected; 
    } 
0

一個簡單的解決方法是從你的aspect方法中調用另一個方法來繼續執行連接點。我只試過在靜態類中調用靜態方法。請參閱下面的代碼,將@InsightOperation添加到我的所有JSON序列化中。

我的方面:

@Aspect 
public class JSONSerializerAspect { 

@Around("call(* *.JSONSerializer.serialize(..)) && args(target)") 
public Object serialize(ProceedingJoinPoint joinPoint, Object target) throws Throwable { 
     return JSONSerializationWrapper.serialize(joinPoint, target); 
    } 
} 

靜態類則呼籲:

public class JSONSerializationWrapper { 

    @InsightOperation(label = "JSON_SERIALIZATION") 
    public static Object serialize(ProceedingJoinPoint joinPoint, Object target) throws Throwable { 
     return joinPoint.proceed(new Object[]{target}); 
    } 

} 

我使用這個自己和測試,它的作品。

相關問題