<dependency> <groupId>org.aopalliance</groupId> <artifactId>aopalliance</artifactId> <version>1.0</version> </dependency> public class LoggingAspect 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; } } HelloService helloService = new HelloServiceImpl(); LoggingAspect loggingAspect = new LoggingAspect(); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTarget(helloService); proxyFactory.addAdvice(loggingAspect); HelloService proxy = (HelloService) proxyFactory.getProxy(); proxy.sayHello();


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