Results 1 to 2 of 2

Thread: Spring aop with struts2

  1. #1
    Join Date
    Mar 2010
    Location
    Chennai
    Posts
    13

    Default Spring aop with struts2

    Hi all,
    I am new to Spring aop and I decided to use aop to track my Struts2 Action class execution time. I have done the following things. But while running the application setter method of the action class is not called.
    Here is my code.
    xml configuration:
    Code:
    <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:aspect>
    	</aop:config>
    Aspect:
    Code:
    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;
    	}
    Action Class:
    Code:
    	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;
    	}
    Thanks in advance.
    With Love ,
    Maheshkumar P

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I suggest

    1) A forum search
    2) A read on the reference guide (especiall chapter 6.6.1)

    Spring uses proxy based aop and only advices beans it knows about. It doesn't know your struts 2 action and hence doesn't advice them.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •