SpringAOP

基于配置文件的方式配置AOP

<aop:config>

配置切点表达式

<aop:pointcut expression="execution(* 类名.*(int,int)) id="pointcut"/>

配置切面及通知

<aop:aspect ref="loggingAspect(上文已经配置过的切面的bean)" order="1(优先级)">

<aop:before method="beforeMethod(方法名)" pointcut-ref="pointcut(上文的切点)"

<aop:after-throwing/>异常抛出

<aop:after-returning/>返回通知

<aop:around/>环绕,全部输出

</aop:aspect>

</aop:config>

基于注解的方式配置AOP

切面

@Order(2)优先级

@Component

@Aspect

public class LoggingAspect{

@Before("execution(类名.*(..))")

public void beforeMethod(JoinPoint joinPoint){}

@AfterReturning(value="execution(public int com.yl.spring.aop.ArithmeticCalculator.*(..))", returning="result")

public void afterReturning(JoinPoint joinPoint, Object result) {}

@AfterThrowing(value="execution(public int com.yl.spring.aop.ArithmeticCalculator.*(..))", throwing="ex")

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 上一篇:Spring学习笔记(七、Spring AOP API) 一、AspectJ介绍与Pointcut注解应用...
    鲁克巴克诗阅读 3,942评论 0 4
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,026评论 19 139
  • AOP实现可分为两类(按AOP框架修改源代码的时机): 静态AOP实现:AOP框架在编译阶段对程序进行修改,即实现...
    数独题阅读 2,350评论 0 22
  • 1. 真正的美就是做自己,你不需要被大部分人认可,你只需要接受最真实的自我!早上好! 2.心里有阳光,雨天也是一种...
    HebbyDong阅读 358评论 3 0
  • 九章 吕可乐怎么也没想到。刘威会去砸飞鱼的场子。她以为,刘威是她最普通的朋友。可接到帮她看到的员工电话时。 吕可乐...
    uiu阅读 380评论 0 1