JAVA全系列 教程
3762个小节阅读:7094.8k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
后置通知是在切入点之后执行的增强。
新建com.bjsxt.advice.MyAfter。
AfterReturningAdvice接口中必须重写afterReturning方法,方法中四个参数:
xxxxxxxxxx
package com.bjsxt.advice;
import org.springframework.aop.AfterReturningAdvice;
import java.lang.reflect.Method;
public class MyAfter implements AfterReturningAdvice {
@Override
public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
System.out.println("后置通知");
}
}
xxxxxxxxxx
<?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
https://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">
<context:component-scan base-package="com.bjsxt.mapper,com.bjsxt.service.impl"></context:component-scan>
<bean id="mybefore" class="com.bjsxt.advice.MyBefore"></bean>
<!-- 配置后置通知bean -->
<bean id="myafter" class="com.bjsxt.advice.MyAfter"></bean>
<aop:config>
<aop:pointcut id="mypoint" expression="execution(* com.bjsxt.service.impl.PeopleServiceImpl.test())"/>
<aop:advisor advice-ref="mybefore" pointcut-ref="mypoint"></aop:advisor>
<!-- 织入后置通知 -->
<aop:advisor advice-ref="myafter" pointcut-ref="mypoint"></aop:advisor>
</aop:config>
</beans>