企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ <?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:context="http://www.springframework.org/schema/context" 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/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 1.注册目标对象 --> <bean name="userService" class="com.nobb.service.UserServiceImpl" ></bean> <!-- 2.注册通知对象 --> <bean name="myAdvice" class="com.nobb.advice.MyAdvice" ></bean> <!-- 3.配置织入(切面) --> <aop:config> <!-- 配置切点 id:为配置的切点起个名字,为了方便后续引用 expression:切点表达式,描述谁是切点 切点表达式语法: execution:描述具体哪个类中的哪个方法需要增强 语法: execution(返回值 包名.类名.方法名(方法参数)) 例子: execution(void com.kaikeba.service.UserServiceImpl.save()) 指定某一个方法为切点 execution(* com.kaikeba.service.UserServiceImpl.save()) 方法返回值任意 execution(* com.kaikeba.service.*ServiceImpl.save()) 指定包中以ServiceImpl结尾的类 execution(* com.kaikeba.service.*ServiceImpl.*()) 空参方法名任意 execution(* com.kaikeba.service.*ServiceImpl.*(..)) 参数列表任意(常用) execution(* com.kaikeba.service.*ServiceImpl.*(Long,..)) 第一个参数是Long型,其他任意. execution(* *..*.*ServiceImpl.*(..)) 任意包下 execution(* *..*.*.*(..)) 所有类中的所有方法都是切点(开玩笑,不常用) --> <aop:pointcut id="myPC" expression="execution(* com.nobb.service.*ServiceImpl.*(..))"/> <!-- 配置切面 切面:切点+通知 ref:指定通知对象 --> <aop:aspect ref="myAdvice" > <!-- 前置切面:切点+前置通知 --> <aop:before method="before" pointcut-ref="myPC"/> <!-- 后置通知 --> <aop:after-returning method="after" pointcut-ref="myPC"/> <!-- 最终通知 --> <aop:after method="end" pointcut-ref="myPC"/> <!-- 异常通知 --> <aop:after-throwing method="afterThrowing" pointcut-ref="myPC"/> </aop:aspect> </aop:config> </beans> ~~~