<beans>
<bean id="testAspectImpl" class="com.kcj.test.TestAspectImpl"></bean>
<bean id="loggingAspect" class="com.kcj.test.LoggingAspect"></bean>
<aop:config>
<aop:pointcut id="pointcut" expression="execution(* com.kcj.test.*.*(..))"></aop:pointcut>
<aop:aspect ref="loggingAspect" order="1">
<aop:before method="before" pointcut-ref="pointcut"/>
<aop:after method="after" pointcut-ref="pointcut"/>
<aop:after-returning method="afterReturning" pointcut-ref="pointcut" returning="result"/>
<aop:after-throwing method="afterThorwing" pointcut-ref="pointcut" throwing="e"/>
</aop:aspect>
</aop:config>
</beans>
package com.kcj.test;
public class TestAspectImpl implements TestAspect{
@Override
public int add(int i, int j) {
return 0;
}
}
package com.kcj.test;
import org.aspectj.lang.JoinPoint;
public class LoggingAspect {
public void declareJoinPointExxcution(){
}
public void before(JoinPoint joinPoint) {
String methodName = joinPoint.getSignature().getName();
Object[] args = joinPoint.getArgs();
}
public void after(JoinPoint joinPoint) {
String methodName = joinPoint.getSignature().getName();
Object[] args = joinPoint.getArgs();
}
public void afterReturning(JoinPoint joinPoint, Object result) {
}
public void afterThorwing(JoinPoint joinPoint, Exception e) {
}
}