Spring AOP配置及通知参数
2013-09-06 10:53
357 查看
使用JoinPoint获取:Spring
AOP提供使用org.aspectj.lang.JoinPoint类型获取连接点数据,任何通知方法的第一个参数都可以是JoinPoint(环绕通知是ProceedingJoinPoint,JoinPoint子类),当然第一个参数位置也可以是JoinPoint.StaticPart类型,这个只返回连接点的静态部分。
AOP配置:
<bean id="logAdvice" class="javacommon.log.LogAdvice"></bean>
<aop:config proxy-target-class="true">
<aop:aspect ref="logAdvice">
<aop:before method="busiLog" pointcut="execution(* com..*Dao.*(..))" />
<aop:before method="busiLog" pointcut="execution(* javacommon.base.*Dao.*(..))" />
<aop:after-throwing throwing="ex" method="afterThrowing" pointcut="execution(* *(..))" />
</aop:aspect>
</aop:config>
通知类:
public class LogAdvice{
public void busiLog(JoinPoint jp) throws Throwable {
System.out.println("====================================");
System.out.println(jp.getSignature().getName());
}
public void afterThrowing(JoinPoint jp, Exception ex){
System.out.println("----------------抛异常了………………");
}
}
当被代理类没有接口时,我们必须使用cglib代理,否则会出现类型转换异常等一堆错误:
AOP提供使用org.aspectj.lang.JoinPoint类型获取连接点数据,任何通知方法的第一个参数都可以是JoinPoint(环绕通知是ProceedingJoinPoint,JoinPoint子类),当然第一个参数位置也可以是JoinPoint.StaticPart类型,这个只返回连接点的静态部分。
AOP配置:
<bean id="logAdvice" class="javacommon.log.LogAdvice"></bean>
<aop:config proxy-target-class="true">
<aop:aspect ref="logAdvice">
<aop:before method="busiLog" pointcut="execution(* com..*Dao.*(..))" />
<aop:before method="busiLog" pointcut="execution(* javacommon.base.*Dao.*(..))" />
<aop:after-throwing throwing="ex" method="afterThrowing" pointcut="execution(* *(..))" />
</aop:aspect>
</aop:config>
通知类:
public class LogAdvice{
public void busiLog(JoinPoint jp) throws Throwable {
System.out.println("====================================");
System.out.println(jp.getSignature().getName());
}
public void afterThrowing(JoinPoint jp, Exception ex){
System.out.println("----------------抛异常了………………");
}
}
当被代理类没有接口时,我们必须使用cglib代理,否则会出现类型转换异常等一堆错误:
<aop:config proxy-target-class="true">
相关文章推荐
- spring Aop 配置文件方式+JoinPoint获取参数
- spring aop五种通知及通知中传递参数!
- 基于xml配置的spring aop 的实现日志 和为通知传递参数
- Spring 配置使用 - AOP 通知参数
- spring aop 配置文件参数介绍
- AOP后置通知获取目标方法的参数以及配置详解
- SpringAOP 处理通知中的参数(注解与xml配置)
- opcache运行时配置参数详解
- Spark配置参数
- 图说hibernate注释--java里配置参数(一.1)
- Sonar分析参数配置
- nginx基本配置与参数说明
- MySQL配置文件my.cnf参数优化和中文详解
- rabbitmq配置&参数详细
- CentOS下修改网络配置参数
- MySQL配置文件my.cnf参数解释
- nginx 基本配置与参数说明详细介绍
- 比较完整的Nginx配置文件nginx.conf常用参数中文详解
- hdfs-site.xml配置参数详情
- nginx 安装、操作命令、基本配置与参数说明