0
我想要做的是有一個方面,它監聽對org.apache.commons.logging.Log.warn的調用並執行一些操作通話結束後。在調用org.apache.commons.logging.Log.warn之前的方面
這可能嗎?
我創造了這樣的一個方面,但它並沒有當我做了LOG.warn曾經被調用:
@Pointcut("execution(* org.apache.commons.logging.Log.warn.*.*(..))")
public void warn() {}
@Around("warn()")
public void collect(JoinPoint joinPoint) throws Throwable {
System.out.println("debug - 1"); // I have a breakpoint here that never gets hit
}
測試類:
private static final Log LOG = LogFactory.getLog(TestCollectMessagesAspect.class);
public String testCall(String param) {
LOG.warn("this is a test");
return param;
}
感謝
嗨,謝謝你的迴應。是的,我控制着這個方法的調用,我只對我們所做的那些感興趣。但是,當我嘗試並使用它時,我收到一個錯誤消息:AOP不支持呼叫連接點... – user3604456
正確。這是記錄的行爲。閱讀http://docs.spring.io/spring/docs/2.0.x/reference/aop.html右側名爲「其他切入點類型」的文本框以供參考。話雖如此,我建議您使用與Spring完美集成的成熟AspectJ。除此之外,Spring AOP只適用於Spring Beans,所以即使Spring AOP中有一個'call()'切入點,它也不適用於Apache Commons Logging之類的非Spring庫。 – kriegaex
好的,謝謝你的信息... – user3604456