[url]http://zywang.iteye.com/blog/974226[/url]
第一种
--------------------------------------
第二种
第三种:
[url]http://www.blogjava.net/javadragon/archive/2006/12/03/85115.html[/url]
第一种
<aop:aspectj-autoproxy/>
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
/**
* 基于注解的AOP日志示例
* @author ZYWANG 2011-3-24
*/
@Component
@Aspect
public class AopLog {
@Pointcut("execution (* com.iflysse.school.services.impl.*.*(..))")
public void pointcut(){}
//方法执行前调用
@Before("pointcut()")
public void before() {
System.out.println("before");
}
//方法执行的前后调用
@Around("pointcut()")
public Object around(ProceedingJoinPoint point) throws Throwable{
System.out.println("begin around");
Object object = point.proceed();
System.out.println("end around");
return object;
}
}
--------------------------------------
第二种
import org.aspectj.lang.ProceedingJoinPoint;
/**
* 基于配置文件的AOP日志示例
* @author ZYWANG 2011-3-24
*/
public class AopLog {
//方法执行的前后调用
public Object runOnAround(ProceedingJoinPoint point) throws Throwable{
System.out.println("begin around");
Object object = point.proceed();
System.out.println("end around");
return object;
}
}
<aop:config>
<aop:aspect ref="aopLog">
<aop:around method="runOnAround" pointcut="execution (* com.zywang.services.impl.*.*(..))"/>
</aop:aspect>
</aop:config>
第三种:
[url]http://www.blogjava.net/javadragon/archive/2006/12/03/85115.html[/url]