<aspect name="LogAspect" class="com.example.LogAspect"> <pointcut expression="execution(* com.example.MyService.*(..))" /> <advice method="logBefore" /> </aspect> public class LogAspect { public void logBefore(JoinPoint joinPoint) { System.out.println("Before executing method: " + joinPoint.getSignature().getName()); } } public class MyService { public void doSomething() { } } public class Main { public static void main(String[] args) { MyService service = new MyService(); Aspectwerkz.aspectOf(LogAspect.class).logBefore(Aspectwerkz.joinPoint(service, "doSomething")); service.doSomething(); } }


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