2010-07-07 157 views
1

我是Spring aop的新手,我決定使用aop來跟蹤我的Struts2 Action類的執行時間。我做了以下事情。但在運行應用程序動作類的setter方法不叫。 這是我的代碼。 xml配置:Spring aop with struts2

<aop:aspectj-autoproxy/> 
<bean id="myAspect" class="abc.xyz.ActionClassAspect"/> 
<aop:config> 
    <aop:pointcut id="actionClassPointcut" expression="execution(public * abc.xyz.action.*.*(..)) 
     and !execution(public * abc.xyz.action.*Action.get*(..)) 
     and !execution(public * abc.xyz.action.*Action.set*(..))"/> 
    <aop:around pointcut-ref="actionClassPointcut" method="doActionClassProfilling"/> 
</aop:config> 

看點:

public Object doActionClassProfilling(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { 
    long start = System.currentTimeMillis(); 
    Object returnValue = proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs()); 
    long end = System.currentTimeMillis(); 
    System.out.println(proceedingJoinPoint.getClass()+" TIME: "+(end-start)); 
    return returnValue; 
} 

動作類別:

private String userID, password; 
@Override 
public String execute() throws Exception { 
    try { 
     LoginService loginService = LoginService.getInstance();; 
     UserProfile userProfile = loginService.validateUser(userID, password); 
     Map<String, Object> sessionMap = ActionContext.getContext().getSession(); 
     sessionMap.put("USER_PROFILE", userProfile); 
     return SUCCESS; 
    } catch(Exception e) { 
     return ERROR; 
    } 
} 
public String getUserID() { 
    return userID; 
} 
public void setUserID(String userID) { 
    this.userID = userID; 
} 
public String getPassword() { 
    return password; 
} 
public void setPassword(String password) { 
    this.password = password; 
} 

預先感謝。

+0

如果你只是想跟蹤執行時間,使用Struts2攔截器會更容易 – 2010-07-07 14:37:13

+0

不僅僅是想跟蹤動作類的執行時間。我想跟蹤整個交易。即。從調用的服務的操作類數量和從該服務調用的每個DAO數量以及這些層的執行時間。 – Maheshkumar 2010-07-08 04:08:14

+0

我想這是一個單獨的模塊。因爲我會在生產時移除這個模塊。 – Maheshkumar 2010-07-08 04:10:16

回答

1

我有這樣的問題,This幫助了我。 我強迫Spring AOP使用CGLIB代理,意識到可能產生的新問題。現在我可以建議我的struts2操作!