第十章 Spring AOP之通知

AOP之通知:

通过配置spring,将通知切入在方法执行前或后,添加打印日志信息,异常信息,获取类名,方法名,参数等

1,前置通知;
2,后置通知;
3,环绕通知;
4,返回通知;
5,异常通知;




<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">

<!-- 定义通知 -->
<bean id="studentServiceAspect" class="com.fx.advice.StudentServiceAspect"></bean>

<!-- 定义业务类 -->
<bean id="studentService" class="com.fx.service.impl.StudentServiceImpl"></bean>

<!-- 业务类配置通知 -->
<aop:config>
<aop:aspect id="studentServiceAspect" ref="studentServiceAspect">
<!-- 切点表达式,匹配包路径下的java -->
<aop:pointcut expression="execution(* com.fx.service.*.*(..))" id="businessService"/>
<!-- 前置通知 -->
<aop:before method="doBefore" pointcut-ref="businessService"/>
<!-- 后置通知 -->
<aop:after method="doAfter" pointcut-ref="businessService"/>
<!-- 环绕通知 -->
<aop:around method="doAround" pointcut-ref="businessService"/>
<!-- 返回通知 -->
<aop:after-returning method="doAfterReturning" pointcut-ref="businessService"/>
<!-- 异常通知 -->
<aop:after-throwing method="doAfterThrowing" pointcut-ref="businessService" throwing="ex"/>
</aop:aspect>
</aop:config>
</beans>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值