Results 1 to 2 of 2

Thread: Advice not working

  1. #1
    Join Date
    Feb 2009
    Posts
    1

    Unhappy Advice not working

    Hi everyone. I'm new to Spring and I am currently working on a project that uses AOP. However, my advice seem to not work at all.
    Here's the configuration:
    Code:
    	
    	<bean id="logInController" class="springmacs.mvc.login.LoginController" > </bean>
    	
    	<bean id="operationLogAdvice" class="springmacs.aop.OperationLogAdvice"/>
    	
    	<bean id="pointcut.advisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
      		<property name="advice" ref="operationLogAdvice"/>
     		<property name="mappedName" value="onSubmit"/>
    	</bean>
    	
    	<bean id="advice" class="org.springframework.aop.framework.ProxyFactoryBean">
    		<property name="interceptorNames">
    			<list>
    				<value>logInController</value>
    				<value>pointcut.advisor</value>
    			</list>
    		</property>
    	</bean>	
    </beans>
    and here's the advice:

    Code:
    public class OperationLogAdvice implements AfterReturningAdvice{    	
    	public void afterReturning(Object returnValue, Method method, Object[] args, 
    	Object target) throws Throwable {
           
           OperationLogService service=new OperationLogService();
           
           OperationLog operationLog=new OperationLog();
    	   OperationLogPK operationLogPK=new OperationLogPK();
    	   
    	   operationLogPK.setTime(TimeUtilities.getCurrentDate().toString());
    	   String log=null;
           
        	   User user=(User) args[2];
        	   operationLogPK.setMacsUserId(user.getUsername());
        	   operationLog.setDescription("Logged in."+ " {"+user.getUsername()+"} "); 
        	   log="\nLogged in."+ " {"+user.getUsername()+"} ";
    
           operationLog.setOperationlogPK(operationLogPK);
           service.insertOperationLog(operationLog);
           System.out.println(log);
                        
       }
    }
    What's wrong here? Please help me... Thanks!

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

    Default

    As always I suggest the reference guide chapter 6.6.1.

    Spring uses proxies for aop, so you can only intercept method calls going INTO the object. the 'onSubmit' for a Controller is an internal method call. Controller has only 1 method you can intercept namely handleRequest.
    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

Posting Permissions

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