在第二篇中,我们已经学习了前置通知和后置通知等,本篇主要讲解环绕通知,环绕通知相对于前置和后置通知来说,有明显的优势。使用环绕通知,我们可以完成前置通知和后置通知所实现的相同功能,而且只需在一个方法中实现。因为整个通知逻辑是在一个方法内实现的,所以不需要使用多个方法。
环绕通知在XML文件中的配置方法与其他类型通知没有太大差异,我们只需使用<aop:around>标签,同时,指定切点和通知方法的名字即可。如下:
<?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
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id=