시소당
package com.youngkun.aoptest;
import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;
public class SimpleBeforeAdvice implements MethodBeforeAdvice{
public static void main(String[] args){
MessageWriter target = new MessageWriter();
ProxyFactory pf = new ProxyFactory();
pf.addAdvice(new SimpleBeforeAdvice());
pf.setTarget(target);
MessageWriter proxy = (MessageWriter)pf.getProxy();
proxy.writeMessage();
}
public void before(Method method, Object[] args, Object target)
throws Throwable{
System.out.println("Before method: "+ method.getName());
}
}
실행
결과
Before method: writeMessage
자기야
출처 : http://youngkun.info/93