AOP

本文介绍Spring框架中的面向切面编程(AOP)应用案例,重点讲解如何通过配置将通用逻辑(如日志记录)与业务逻辑分离,实现模块化管理。展示了如何定义切面、切入点及通知类型,并提供了具体的XML配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

aop 面向切面编程, 把一个通用的方法提出,通过配置文件的配置,织入到其他方法中,可以在方法前后调用此切面方法
spring中的aop是方法的横切问题
使用场合:
1)一般不涉及业务的,比如:日志功能
2)JoinPoint 织入的方法的参数, 能得到某个被干预方法的参数
changeObj(JoinPoint joinPoint){
Object[] args = joinPoint.getArgs();
}
3)缺点: 只能得到被干预方法的参数,不易做业务处理
例子如下:
在spring中的配置文件:
//切面方法的类
<bean id="securityHandler" class="com.harmony.dsmanage.recordchange.service.impl.SecurityHandler"/>

<aop:config>
//方面=advice(通知)+pointcut
<aop:aspect id="securityOne" ref="securityHandler">
//切入点
<aop:pointcut id="allAddMethod" expression="execution(* MyServiceImpl.save*(..))"/>
//切入时机
<aop:before method="changeObj" pointcut-ref="allAddMethod"/>
</aop:aspect>
<aop:aspect id="securityDangerMatter" ref="securityHandler">
<aop:pointcut id="allAddMethod2" expression="execution(* MyServiceImpl.save*(..))"/>
<aop:before method="changeObj" pointcut-ref="allAddMethod2"/>
</aop:aspect>
</aop:config>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值