Announcement Announcement Module
Collapse
No announcement yet.
Advice not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment

    Working...
    X