@Around("execution(* com.example.service.*.*(..))") public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable { System.out.println("Before method execution"); Object result = joinPoint.proceed(); System.out.println("After method execution"); return result; } public class LoggingAdvice implements MethodInterceptor { @Override public Object invoke(MethodInvocation invocation) throws Throwable { System.out.println("Before method execution"); Object result = invocation.proceed(); System.out.println("After method execution"); return result; } } public class MyService { public void doSomething() { System.out.println("Doing something"); } } public static void main(String[] args) { MyService myService = new MyService(); ProxyFactory proxyFactory = new ProxyFactory(myService); proxyFactory.addAdvice(new LoggingAdvice()); MyService proxy = (MyService) proxyFactory.getProxy(); proxy.doSomething(); }


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