<dependency>
<groupId>org.aspectwerkz</groupId>
<artifactId>aspectwerkz-core</artifactId>
<version>2.3.0</version>
</dependency>
import org.aspectwerkz.aspect.DefaultCatch;
import org.aspectwerkz.aspect.GenericAbstractInterceptor;
import org.aspectwerkz.joinpoint.JoinPoint;
public class LoggingAspect extends GenericAbstractInterceptor {
public Object logMethodExecution(JoinPoint joinPoint) {
System.out.println("Before executing method: " + joinPoint.toString());
Object result = null;
try {
result = joinPoint.proceed();
System.out.println("After executing method: " + joinPoint.toString());
} catch (Throwable throwable) {
System.out.println("Exception occurred while executing method: " + joinPoint.toString());
throwable.printStackTrace();
}
return result;
}
}
public class SampleClass {
@Joinpoint(interceptor = LoggingAspect.class, pointcut = "execution(* com.example.SampleClass.*(..))")
public void doSomething() {
}
}
<bean id="loggingAspect" class="com.example.LoggingAspect" />
<aop:config>
<aop:aspect id="aspectLogging" ref="loggingAspect">
<aop:pointcut id="loggingPointcut"
expression="execution(* com.example.SampleClass.*(..))" />
<aop:around method="logMethodExecution"
pointcut-ref="loggingPointcut" />
</aop:aspect>
</aop:config>