2010-07-07 158 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操作!