第一章:Spring AOP 总览

AOP 常见使用场景

日志场景
• 诊断上下文,如:log4j 或 logback 中的 _x0008_MDC
• 辅助信息,如:方法执行时间
统计场景
• 方法调用次数
• 执行异常次数
• 数据抽样
• 数值累加
安防场景
• 熔断,如:Netflix Hystrix
• 限流和降级:如:Alibaba Sentinel
• 认证和授权,如:Spring Security
• 监控,如:JMX
性能场景
• 缓存,如 Spring Cache
• 超时控制

Java AOP 设计模式

*代理模式:静态和动态代理
• 判断模式:类、方法、注解、参数、异常…
• 拦截模式:前置、后置、返回、异常
• Java 静态代理
• 常用 OOP 继承和组合相结合
• Java 动态代理
• JDK 动态代理
• 字节码提升,如 CGLIB

Java AOP 判断模式(Predicate)

判断来源
• 类型(Class) • 方法(Method) • 注解(Annotation) • 参数(Parameter) • 异常(Exception)

Java AOP 拦截器模式(Interceptor)

拦截类型
• 前置拦截(Before) • 后置拦截(After) • 异常拦截(Exception)

Spring AOP 功能概述

核心特性
• 纯 Java 实现、无编译时特殊处理、不修改和控制 ClassLoader
• 仅支持方法级别的 Join Points
• 非完整 AOP 实现框架
• Spring IoC 容器整合
• AspectJ 注解驱动整合(非竞争关系)

Spring AOP 编程模型

注解驱动
• 实现:Enable 模块驱动,@EnableAspectJAutoProxy
• 注解:
• 激活 AspectJ 自动代理:@EnableAspectJAutoProxy
• Aspect : @Aspect
• Pointcut :@Pointcut
• Advice :@Before、@AfterReturning、@AfterThrowing、@After、@Around
• Introduction :@DeclareParents
XML 配置驱动
• 实现:Spring Extenable XML Authoring
• XML 元素
• 激活 AspectJ 自动代理:aop:aspectj-autoproxy/
• 配置:aop:config/
• Aspect : aop:aspect/
• Pointcut :aop:pointcut/
• Advice :aop:around/、aop:before/、aop:after-returning/、aop:after-throwing/ 和
aop:after/
• Introduction :aop:declare-parents/
• 代理 Scope : aop:scoped-proxy/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值