Hi all, I tried to apply AOP to Struts2 action classes. My configurations are:
<aop:aspectj-autoproxy proxy-target-class="true"/>
<aop:aspect id="actionAspect" ref="actionClassAspect">
<aop:around method="doAspect" pointcut-ref="actionClassPointcut"/>
</aop:aspect>
my action class is:
package com.rpm.application.common.web.action;
import com.opensymphony.xwork2.ActionSupport;
public class ApplicationLoginAction extends ActionSupport { private String userID, password;
@Override
public String execute() throws Exception {
try {
//validation logic
System.out.println("Login success");
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;
}
}
my aspect is:
package com.rpm.application.profiling;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Aspect;
@Aspect public abstract class ActionClassAspect { public Object doAspect(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { long start = System.currentTimeMillis(); Object returnValue = proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs()); long end = System.currentTimeMillis(); System.out.println(" " + proceedingJoinPoint.getTarget().getClass() + " KIND:" + proceedingJoinPoint.getSignature().toShortString() + " TIME: " + (end - start)); return returnValue; } }
When I executing this application on tomcat6.x server AOP is not applied to that action class.