SSISO Community

시소당

AOP 예제3 - After Returning Advice

package com.youngkun.aoptest;

import java.lang.reflect.Method;

import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.framework.ProxyFactory;

public class SimpleAfterReturningAdvice implements AfterReturningAdvice{
   public static void main(String[] args) {
       MessageWriter target = new MessageWriter();
      
       ProxyFactory pf = new ProxyFactory();
      
       pf.addAdvice(new SimpleAfterReturningAdvice());
       pf.setTarget(target);
      
       MessageWriter proxy = (MessageWriter)pf.getProxy();
      
       proxy.writeMessage();
   }
  
   public void afterReturning(Object returnValue, Method method, Object[] args, Object target)
       throws Throwable{
       System.out.println("");
       System.out.println("After method: " + method.getName());
   }
}


실행결과

자기야
After method: writeMessage

 

출처 : http://youngkun.info/94

736 view

4.0 stars