import org.aopalliance.aop.Advice; import org.aopalliance.intercept.MethodInterceptor; public class LoggingAdvice implements MethodInterceptor{ public Object invoke(MethodInvocation methodInvocation) throws Throwable { System.out.println("Before method: " + methodInvocation.getMethod().getName()); Object result = methodInvocation.proceed(); System.out.println("After method: " + methodInvocation.getMethod().getName()); return result; } } public class ExampleClass { public void doSomething(){ System.out.println("Doing something..."); } } public class Main { public static void main(String[] args) { ExampleClass example = new ExampleClass(); ProxyFactory factory = new ProxyFactory(example); factory.addAdvice(new LoggingAdvice()); ExampleClass proxy = (ExampleClass) factory.getProxy(); proxy.doSomething(); } }


上一篇:
下一篇:
切换中文