<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();
}
}